如何访问对其他对象的引用的appuser属性? (asp.net/efcore)
我有一个从IdentityUser继承并包含一个清单对象的Appuser类:
public class AppUser : IdentityUser
{
public InventoryModel? Inventory { get; set; }
}
我一直在使用此行来使当前用户具有其所有属性:
var user = await _userManager.GetUserAsync(User);
我可以以这种方式访问Appuser中的任何原始数据类型,但似乎要懒惰,不要随身携带库存。我已经手动查询了我的数据库,看到我得到的用户有一个库存。14(库存类的主要密钥标识符),但是当我使用上述语句获取用户时,他们的库存始终为null 。
是否有某种可以与getuserasync一起使用的“ .include()”?我应该这样做的另一种方式吗?
I have an AppUser class that inherits from IdentityUser and contains an Inventory object:
public class AppUser : IdentityUser
{
public InventoryModel? Inventory { get; set; }
}
I've been using this line to get the current user with all their properties:
var user = await _userManager.GetUserAsync(User);
Any primitive data types I put in AppUser can be accessed this way, but it seems to be lazy loading and not bringing the inventory along with it. I have manually queried my database and I see that the user I'm getting has an Inventory.InventoryId of 14 (primary key identifier for the Inventory class), but when I use the above statement to get the user, their Inventory is always null.
Is there some kind of ".Include()" that can be used with GetUserAsync? Is there another way I should be doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何同样问题的人来说,寻找快速解决方案:
正如Eldar建议的那样,我注入了
applicationdbcontext
,然后做了这样的事情:它非常不高,但是从技术上讲,它可以完成我想完成的工作。
For anyone with this same issue looking for a quick fix:
As Eldar suggested, I injected the
ApplicationDbContext
and then did something like this:It's pretty inelegant but technically it accomplish what I wanted to accomplish.