Optional One-to-many Relationship in Entity Framework

前端 未结 3 941
有刺的猬
有刺的猬 2021-01-18 14:25

I\'m having issues getting an optional one-to-many relationship to work.

My model is:

public class Person
{
    public int Identifier { get; set; }
          


        
3条回答
  •  余生分开走
    2021-01-18 14:39

    You can try this:

    this.HasOptional(s => s.Department)
        .WithMany(s => s.Members)
        .HasForeignKey(s => s.MemberOfDepartment);
    

提交回复
热议问题