【发布时间】:2011-05-12 15:14:48
【问题描述】:
class First
{
[Key]
public int Id { get; set; }
}
class Second
{
[Key]
public int Id { get; set; }
public int? First_Id { get; set; }
[ForeignKey("First_Id")]
public First First { get; set; }
}
public class SecondMapping : EntityTypeConfiguration<Second>
{
public SecondMapping ()
: base()
{
this.HasOptional(s => s.First)
.With ... ???
}
}
Second 可能引用了 First。但是 First 从来没有提到过 Second。是否可以将此映射与 Entity Framework 4.1 一起应用?
编辑: 以前,这是我的解决方案:
this.HasOptional(s => s.First)
.WithOptionalDependent()
.WillCascadeOnDelete(false);
Second 可以包含 First 的一个实例(取决于某种使用属性)。 First 不包含 Second 的任何实例。
【问题讨论】:
标签: c# entity-framework foreign-keys