实体框架仅按条件包括项目 [英] Entity Framework include items only by condition

查看:63
本文介绍了实体框架仅按条件包括项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要上下文根据条件包含 sonns ,我需要未删除的行(逻辑删除)。

I need my context to include the sonns by a condition, I need the rows that not deleted (logical delete).

我知道我不能在包含中添加条件;所以我想过滤上下文,但是它不起作用。

I understood that I cannot add a condition to the include; so I want to filter the context, but it's not working.

var aa = ctx.aa
         .Include(t => t.vari)
         .ToList()
         .FirstOrDefault();

ctx.vari.Where(bi => bi.ID == 10 && bi.Deleted == 1).ToList();

谢谢!

推荐答案

为codelahiru&&

As codelahiru && hbulens pointed out, you missed the bi for ID.

免责声明:我是项目的所有者实体框架增强版

Disclaimer: I'm the owner of the project Entity Framework Plus

查询IncludeOptimized功能可过滤包含并优化同时查询性能(支持EF5,EF6)

The Query IncludeOptimized feature allows to filter with include and optimize the query performance at the same time (Support EF5, EF6)

var aa = ctx.aa
            .IncludeOptimized(t => t.vari.Where(bi => bi.ID == 10 && bi.Deleted == 1))
            .FirstOrDefault();

文档:包含EF +查询的已优化

这篇关于实体框架仅按条件包括项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆