I am using EF5 and I need to create the following relationships
- one-to-one between SavedApplicationQueue and SavedApplication
- one-to-one between BatchApplicationQueue and BatchApplication
public abstract class BaseEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int Id { get; set; }
}
public abstract class Queue : BaseEntity
{
public string Status { get; set; }
public DateTime? LastRun { get; set; }
}
public abstract class Application : BaseEntity
{
public string ApplicationInhertirot { get; set; }
public string AnotherApplicationInhertirot { get; set; }
}
public class BatchApplication : Application
{
public bool BatchAppFlag { get; set; }
public string BatchAppString { get; set; }
public virtual BatchApplicationQueue BatchApplicationQueue { get; set; }
}
public class SavedApplication : Application
{
public bool SavedAppFlag { get; set; }
public string SavedAppString { get; set; }
public virtual SavedApplicationQueue SavedApplicationQueue { get; set; }
}
public class SavedApplicationQueue : Queue
{
[Required]
[ForeignKey("SavedApplication")]
public virtual SavedApplication SavedApplication { get; set; }
}
public class BatchApplicationQueue :Queue
{
[Key]
[ForeignKey("BatchApplication")]
public override int Id { get; set; }
[Required]
public virtual BatchApplication BatchApplication { get; set; }
}
the fluent I have is
modelBuilder.Entity<Application>()
.Map<SavedApplication>(m =>
{
m.ToTable("SApplication");
m.MapInheritedProperties();
})
.Map<BatchApplication>(m =>
{
m.ToTable("BApplication");
m.MapInheritedProperties();
});
modelBuilder.Entity<Queue>()
.Map<SavedApplicationQueue>(m =>
{
m.ToTable("SavedApplicationQueue");
m.MapInheritedProperties();
})
.Map<BatchApplicationQueue>(m =>
{
m.ToTable("BatchApplicationQueue");
m.MapInheritedProperties();
});
the problem I have is when I try and create/add record
Test method Ef.Model.Test.UnitTest1.TestMethod1 threw exception: System.InvalidOperationException: Sequence contains more than one matching element
I think it has something to do with the Id but I am simply trying to create the relationships and multiplicity as described