Entity Framework Core nullable foreign key

后端 未结 1 816
有刺的猬
有刺的猬 2021-01-17 20:17

I am having trouble getting a list of entities where a foreign key value could be null.

The Models:

public class Company
{
    [Key]         


        
相关标签:
1条回答
  • 2021-01-17 21:02

    Supposing that it did actually return mary, what would you expect her CompanyId to be? I would suspect null (what else could it be?), in which case your model is wrong and public int CompanyId { get; set; } should be public int? CompanyId { get; set; }

    0 讨论(0)
提交回复
热议问题