In my Asp.net Core 2.0 app I have an ApplicationUser class where I store names and info. But I also have set a navigation property which is a class called "Company" there.
I use this in my controller to get the current user:
var person = await _userManager.GetUserAsync(User);
The problem is that the navigation property is not included in this(the other properties are however. person.Company is null). Is there a way to include it using userManager or do I have to call the ApplicationUser table again after this?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
143 Points
165 Posts
How to get navigation properties from userManager?
Sep 01, 2017 08:54 AM|bluMarmalade|LINK
In my Asp.net Core 2.0 app I have an ApplicationUser class where I store names and info. But I also have set a navigation property which is a class called "Company" there.
I use this in my controller to get the current user:
The problem is that the navigation property is not included in this(the other properties are however. person.Company is null). Is there a way to include it using userManager or do I have to call the ApplicationUser table again after this?
Contributor
6680 Points
2715 Posts
Re: How to get navigation properties from userManager?
Sep 04, 2017 07:04 AM|Eric Du|LINK
Hi bluMarmalade,
According to your description and code, I think you use lazy loading, if you use lazy loading, please check the following rules:
Rules for lazy loading:
For more details, please check this tutorial link:
Lazy Loading:
http://www.entityframeworktutorial.net/EntityFramework4.3/lazy-loading-with-dbcontext.aspx
I suggest you could use Include() method of eager loading, please check: Eager Loading:
http://www.entityframeworktutorial.net/EntityFramework4.3/eager-loading-with-dbcontext.aspx
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.