我不知道on c.blah equals b.blah
在LINQ的一个连接语句中可能有嵌套或2个或更多嵌套的原因,因为我必须在不影响数据数量的情况下连接表
因为如果我将它添加到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 }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句