외래 키 값이 null 일 수있는 엔터티 목록을 가져 오는 데 문제가 있습니다.Entity Framework null nullable 외래 키
모델 :
public class Company
{
[Key]
[Required]
public int Id { get; set; }
[Display(Name = "Company Name")]
public string CompanyName { get; set; }
[Display(Name = "Main Phone")]
public string LandPhone { get; set; }
[Display(Name = "Fax")]
public string FaxPhone { get; set; }
}
public class Contact
{
[Key]
[Required]
public int Id { get; set; }
[Display(Name ="First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
[EmailAddress]
public string Email { get; set; }
[Display(Name = "Mobile Phone")]
public string MobilePhone { get; set; }
[Display(Name = "Office Phone")]
public string LandPhone { get; set; }
[Display(Name = "Fax")]
public string FaxPhone { get; set; }
public string Title { get; set; }
public int CompanyId { get; set; }
[ForeignKey("CompanyId")]
public Company Company { get; set; }
}
나는 시도하고 내 데이터베이스에 CompanyId
에 대한 널 (null) 값이이 목록에 Contact
그것을 반환 건너 뜁니다 한 모든 Contacts
그 중 하나의 목록을 . 예를 들어, 쿼리 var contacts = _context.Contacts.Include(c => c.Company).ToList();
은 다음 표에서 조스 스톤을 반환
것은 내가 엔티티 프레임 워크 핵심 1.0.0을 사용하고 있습니다. 어떤 도움도 진심으로 감사 할 것입니다.