通用工作单位和仓库模式不加载相关实体

编程入门 行业动态 更新时间:2024-10-27 04:29:43
本文介绍了通用工作单位和仓库模式不加载相关实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我实际上有一个之前的帖子。然后,我意识到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();

更多推荐

通用工作单位和仓库模式不加载相关实体

本文发布于:2023-11-06 22:23:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   仓库   加载   单位   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!