相关疑难解决方法(0)

有条件的包含在linq中的实体?

我觉得以下应该是可能的我只是不确定采取什么方法.

我想要做的是使用include方法来塑造我的结果,即定义沿着对象图遍历的距离.但是......我希望这种遍历是有条件的.

something like...

dealerships
    .include( d => d.parts.where(p => p.price < 100.00))
    .include( d => d.parts.suppliers.where(s => s.country == "brazil"));
Run Code Online (Sandbox Code Playgroud)

我知道这不是有效的linq,事实上,它是非常错误的,但实质上我正在寻找一些方法来构建一个表达树,它将返回形状结果,相当于......

select *
from dealerships as d
outer join parts as p on d.dealerid = p.dealerid
    and p.price < 100.00
outer join suppliers as s on p.partid = s.partid
    and s.country = 'brazil'
Run Code Online (Sandbox Code Playgroud)

重点是加入条件.

我觉得这对esql来说是相当直接的,但我最喜欢的是动态构建表达式树.

一如既往,感谢任何建议或指导

linq conditional entity-framework include

21
推荐指数
2
解决办法
2万
查看次数

Linq包含where子句

嘿,所以我遇到了这样一种情况,即我将客户从数据库中拉回来并通过包含所有案例研究

return (from c in db.Clients.Include("CaseStudies")
        where c.Id == clientId
        select c).First();
Run Code Online (Sandbox Code Playgroud)

但我现在要做的是和所包含的casestudies的where子句,以便它只返回案例研究,其中deleted = false

有点像这样

return (from c in db.Clients.Include("CaseStudies")
        where c.Id == clientId
        && c.CaseStudy.Deleted == false
        select c).First();
Run Code Online (Sandbox Code Playgroud)

但这不起作用:(任何想法

linq include where-clause

4
推荐指数
1
解决办法
1万
查看次数