如何在一个实体中实现没有链接的1:1关系?
public class Foo
{
public int Id { get; set; }
...
}
public class Bar
{
public int Id { get; set; }
public int FooId { get; set; }
public virtual Foo Foo { get; set; }
...
}
Fluent API:
Entity<Bar>.HasKey(bar => bar.FooId)
.HasRequired(bar=> bar.Foo)
.WithMany()
.HasForeignKey(p => p.FooId)
.WillCascadeOnDelete(false);
及其在数据库中一对多创建