我有这堂课:
public class CommunityUser : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int CustomerId { get; set; }
public DateTime CreatedOnUtc { get; set; }
public int ForumPostsNumber { get; set; }
public virtual Customer Customer { get; set; }
}
如何使用实体框架映射来表示CommunityUser有一个可选的CustomerId,它是Customer Table上的外键?
答案 0 :(得分:1)
您必须通过将其设为int?
public class CommunityUser : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int? CustomerId { get; set; }
public DateTime CreatedOnUtc { get; set; }
public int ForumPostsNumber { get; set; }
public virtual Customer Customer { get; set; }
}