Asp.net mvc 检索MVC 5标识中的链接用户配置文件属性

Asp.net mvc 检索MVC 5标识中的链接用户配置文件属性,asp.net-mvc,asp.net-identity,Asp.net Mvc,Asp.net Identity,我正在使用标识为V2的MVC 5,在搜索用户时无法获取链接属性 我的身份用户模型如下: public class ApplicationUser : IdentityUser { public string FullName { get; set; } public School School { get; set; } public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserMana

我正在使用标识为V2的MVC 5,在搜索用户时无法获取链接属性

我的身份用户模型如下:

public class ApplicationUser : IdentityUser
{
    public string FullName { get; set; }

    public School School { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        return userIdentity;
    }
}
然后正确填充currentUser,我有FullName的值,但是School的值为null

AspNetUsers的数据库表包含一个名为School_SchoolID的字段,该字段包含一个引用School表中正确记录的值


如何检索链接学校属性的详细信息?

如果希望学校信息与用户配置文件一起加载,则学校属性应为虚拟属性

public virtual School School { get; set; }

您没有显示FindById的代码,这不是因为没有返回完整的ApplicationUser对象而无法正常工作的函数吗?FindById内置于Identity Framework中,它不是我编写的函数检查数据库中ApplicationUser表和学校之间的正确关系,如果不是,使用EF code first时必须正确绑定模型。DSR是正确的,问题可能在于如何设置ApplicationUser和School表之间的代码优先关系。显示两个实体的代码以及如何设置它们之间的关系。您说AspNetUsers表包含一个field School\u SchoolID,但我没有看到它在ApplicationUser中定义。
public virtual School School { get; set; }