【发布时间】:2016-06-11 18:52:43
【问题描述】:
我在模板模型中扩展了ApplicationUser 类以包含一个可选公司:
public class ApplicationUser : IdentityUser
{
public virtual Guid? CompanyID { get; set; }
public virtual Company Company { get; set; }
}
在“公司”类中,我包含了ApplicationUsers 的集合:
[Required]
[Key]
public Guid? CompanyId { get; set; }
public virtual ICollection<ApplicationUser> Users { get; set; }
我是否还需要在ModelBuilder 中为ApplicationdbContext 指定关系?还是 Code-First 应该为我处理这个问题?
我问是因为当我在控制器中抓取_context.Users.ToList() 时,Company 始终是null,即使为ApplicationUser 填充了CompanyID。
【问题讨论】:
-
这已经奏效了。你介意解释一下原因吗?
标签: asp.net-mvc entity-framework ef-code-first