Generic Unit of Work and Repository pattern does not load related entities

风流意气都作罢 提交于 2019-12-25 02:55:53

问题


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.

When I use the .Include() extension in the DBSet<> property, the relationships begin populating without issue.

This works:

var list = (new DBContext()).Teams.Include(a => a.Creator).AsQueryable().ToList();

Using the repository does not work:

var list = _repo.Queryable().ToListAsync();

Any help, please?

UPDATE FIX:

Thanks to DLeh for the idea! Here's my fix:

var list = _repo.Queryable().Include(a => a.Creator).ToListAsync();

回答1:


It's solved. Thanks to DLeh for the idea.

var list = _repo.Queryable().Include(a => a.Creator).ToListAsync();


来源:https://stackoverflow.com/questions/29542993/generic-unit-of-work-and-repository-pattern-does-not-load-related-entities

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