C# 来自sql联接的LINQ
我试图理解如何在LINQ中重写连接查询C# 来自sql联接的LINQ,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我试图理解如何在LINQ中重写连接查询 SELECT cs.qid,cs.qk FROM location_table pl JOIN (SELECT qid,qk FROM q_table WHERE att5 = 'process') cs ON pl.qck = cs.qk WHERE pl.location = 'there' 这是我开始使用的LINQ,但它返回的结果与上面的SQL不同 from pl in location_table from cs in q_table wher
SELECT cs.qid,cs.qk FROM location_table pl
JOIN (SELECT qid,qk FROM q_table WHERE att5 = 'process') cs ON pl.qck = cs.qk
WHERE pl.location = 'there'
这是我开始使用的LINQ,但它返回的结果与上面的SQL不同
from pl in location_table
from cs in q_table
where s. att5 == 'process'
&& cs.qk == pl.qck
&& pl. location == 'there'
谢谢你的帮助 您需要使用
join
关键字
from pl in location_table
join cs in q_table
on cs.qk equals pl.qck
where cs.att5 == ‘process’ && pl. location == ‘there’
select new{cs.qid, cs.qk}
如果您想将其重写为存在
,因为只需要q_表的输出:
SELECT qid,qk
FROM q_table AS cs
WHERE EXISTS
(
SELECT 1
FROM location_table pl
WHERE pl.qck = cs.qk AND pl.location = 'there'
)
AND cs.att5 == 'process'
您可以这样做:
from cs in q_table
where location_table.All(pl=>pl.qck == cs.qk && pl.location == 'there')
&& cs.att5 == 'process'
select new{cs.qid, cs.qk}
他们最终应该得到相同的结果。我将把性能检查留给您:)您需要使用
join
关键字
from pl in location_table
join cs in q_table
on cs.qk equals pl.qck
where cs.att5 == ‘process’ && pl. location == ‘there’
select new{cs.qid, cs.qk}
如果您想将其重写为存在
,因为只需要q_表的输出:
SELECT qid,qk
FROM q_table AS cs
WHERE EXISTS
(
SELECT 1
FROM location_table pl
WHERE pl.qck = cs.qk AND pl.location = 'there'
)
AND cs.att5 == 'process'
您可以这样做:
from cs in q_table
where location_table.All(pl=>pl.qck == cs.qk && pl.location == 'there')
&& cs.att5 == 'process'
select new{cs.qid, cs.qk}
他们最终应该得到相同的结果。我将把性能检查留给您:)您是否尝试过使用显式联接
from pl in location_table
join cs in q_table on cs.qk equals pl.qck
where s. att5 == 'process'
&& pl. location == 'there'
您是否尝试过使用显式联接
from pl in location_table
join cs in q_table on cs.qk equals pl.qck
where s. att5 == 'process'
&& pl. location == 'there'
看一看这张照片。该链接专门用于连接,对您来说是一个很好的起点。该链接专门用于连接,将是您的一个很好的起点。Hmmm现在遇到了一个比较int和字符串cs.qk等于pl.qck的问题。我尝试使用SqlFunctions.StringConvert,但也不起作用。好吧,oracle EFHmmm似乎不支持SqlFunctions,现在遇到了比较int和字符串cs.qk等于pl.qck的问题。我试过使用SqlFunctions.StringConvert,但也不起作用。好吧,看来oracle EF不支持SqlFunctions