本文介绍了通用工作单位和仓库模式不加载相关实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实际上有一个之前的帖子。然后,我意识到EF内置了一个懒惰的加载配置,并且看起来通用工作单元和存储库模式框架不自动加载相关实体。
I actually had a previous post regarding the topic that I first thought was an EF issue. I then realized that EF has a lazy loading configuration built in and it appears that the Generic Unit of Work and Repository Pattern framework is not loading related entities automatically.
当我在DBSet<>属性中使用.Include()扩展名时,关系开始填充没有问题。
When I use the .Include() extension in the DBSet<> property, the relationships begin populating without issue.
这样做:
var list = (new DBContext()).Teams.Include(a => a.Creator).AsQueryable().ToList();使用存储库不起作用:
var list = _repo.Queryable().ToListAsync();请帮助吗?
UPDATE FIX:
感谢DLeh的想法! 这是我的修复:
Thanks to DLeh for the idea! Here's my fix:
var list = _repo.Queryable().Include(a => a.Creator).ToListAsync();推荐答案
感谢DLeh的想法。
var list = _repo.Queryable().Include(a => a.Creator).ToListAsync();更多推荐
通用工作单位和仓库模式不加载相关实体
发布评论