我正在使用 EF5,我需要创建以下关系
- SavedApplicationQueue 和 SavedApplication 之间的一对一
- BatchApplicationQueue 和 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; }
}
我的流利程度是
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();
});
我遇到的问题是当我尝试创建/添加记录时
测试方法 Ef.Model.Test.UnitTest1.TestMethod1 抛出异常:System.InvalidOperationException:序列包含多个匹配元素
我认为这与身份有关,但我只是想创建所描述的关系和多样性