I am working in visual studio 2017, i created a web with this properties:
asp.net
mvc
individual User Account
But i changed the model of AspNetUser:
In Models:
ApplicationUser (add)
{
...
[ForeignKey]
[InverseProperty("ApplicationUser")]
public virtual UserProfile UserProfile {get; set;}
}
UserProfile
{
...
[InverseProperty("UserProfile")]
public virtual ApplicationUser ApplicationUser {get; set;}
[ForeignKey]
[InverseProperty("UserProfile")]
public virtual UserImage {get; set;}
}
UserImage
{
...
[InverseProperty("UserImage")]
public virtual UserProfile {get; set;}
}
Later i do a migration in nuget console, when in my view save my user with their profile, this work fine (i did a check in my db), but, when i try to get the user's profile is null.
I used this code. In my controller AccountController for my view UpdateUser i put this
private readonly UserManager<ApplicationUser> _userManager;
public AccountController(..., UserManager<ApplicationUser> userManager) {
this._userManager = userManager;
....
}
public async Task<IActionResult> UpdateUser() {
ApplicationUser currentUser = await _userManager.GetUserAsync(User);
...
}
Now, when my controller in the function UpdateUser do action await _userManager.GetUserAsync(User), this load not open the related table UserProfile because of that the field UserProfile in currentUser is null. In asp.net 5 i can load this profile using HttpContext.GetOwinContext<applicationDbContext>() but aspnetcore don't has this
How i can do that (or What do I have to change so that the function GetUserAsync(User) load the user and their profile automatically)?