gpt4 book ai didi

c# - 是否可以在 Linq 的 1 个连接语句中添加多个 'on'

转载 作者:行者123 更新时间:2023-11-29 02:24:31 25 4
gpt4 key购买 nike

我不知道在 LINQ 的一个连接语句中有嵌套的或 2 个或更多的 on c.blah equals b.blah 因为我必须连接一个表而不影响数据数量

因为如果我将它添加到 where 那里,数据数量会减少,它会充当过滤器

我目前尝试的是添加 && 子句,但它不起作用

var Pos =  (from a in db.Position
join b in db.Position_Location
on a.ID equals b.PositionId
join c in db.Customer
on a.CustomerID equals c.ID
join d in db.Customer_Location
on b.LocationId equals d.ID
join f in db.Worker
on userIdNew equals f.userId
join e in db.Worker_Customer_Apply_Shift <----Planning to add new validation here
on a.ID equals e.Client_Customer_PositionID into trial
from newtrial in trial.DefaultIfEmpty()
where
b.LogicalDelete == false
&& a.LogicalDelete == false
&& c.LogicalDelete == false
&& d.LogicalDelete == false

select new
{
a.ID,
Client_CustomerID = c.ID,
LogicalDelete =(newtrial == null ? true : newtrial.LogicalDelete),


}).Distinct().ToList();

提前致谢:)

最佳答案

您可以对要在连接条件中使用的字段使用匿名类型:

on new { a.One, a.Two } equals new { b.One, b.Two }

如果两个表中的列名称不同,则需要为匿名类型的属性提供名称:

on new { Col1 = a.One, Col2 = a.Two } equals new { Col1 = b.Three, Col2 = b.Four }

关于c# - 是否可以在 Linq 的 1 个连接语句中添加多个 'on',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25151956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com