How do I tell UserManager.FindByIdAsync(userid); to include a relation?

放肆的年华 提交于 2019-12-11 02:05:31

问题


I added a new property and its corresponding table to my database using ASP.NET Identity with Code First like so:

public class ApplicationUser : IdentityUser
 {
    ....

    public virtual ICollection<File> Files { get; set; }       
 }


public class File
{    
  ..
  public virtual ApplicationUser UserManager { get; set; }

}

Now, from some action, when I call:

  var user = await UserManager.FindByIdAsync(userid);

it does get the user with the correct userid

I want to Include method in Entity Framework to include the navigational property or relation named File (of type File) on the ApplicationUser class.

How do I do that with ASP.NET Identity's UserManager? I suspect the only way would be to override this method in my custom UserManager derived class and do it myself?

I'm trying replace code

var user = await UserManager.Include(u => u.Files).FindByIdAsync(userid);

来源:https://stackoverflow.com/questions/34941521/how-do-i-tell-usermanager-findbyidasyncuserid-to-include-a-relation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!