Entity Framework table with multiple optional one to one relationships

前端 未结 1 1120
攒了一身酷
攒了一身酷 2020-12-21 19:40

There are a few questions out there but none of them have been much help to me so I decided to ask my own.

I want to use Entity Framework code first to create a st

相关标签:
1条回答
  • 2020-12-21 19:49

    In your mappings you set Document as principal, but in reality it is the dependent. So you should change your mappings to:

    modelBuilder.Entity<Document>()
        .HasRequired(d => d.Qualification)
        .WithOptionalDependent(q => q.Document);
    
    modelBuilder.Entity<Document>()
        .HasRequired(d => d.Asssessment)
        .WithOptionalDependent(q => q.Document);
    
    0 讨论(0)
提交回复
热议问题