如何优化linq查询 [英] How to optimize linq query
问题描述
var rows1 = (from bb in dt3.AsEnumerable()
where (bb.Field<string>("Request_ID") == Convert.ToString(newDt2.Rows[i1]["Request_ID"])
&& bb.Field<string>("Route_Header_ID") == Convert.ToString(newDt2.Rows[i1]["Route_Header_ID"]))
select bb);
什么我试过了:
使用join来优化这个,但得到错误的结果。可能是我无法使用
What I have tried:
use join to optimize this,but getting wrong result.May be i am not able to doing correct syntax using
推荐答案
做正确的语法首先,请阅读我对这个问题的评论。
问题的答案:如何优化linq查询? - 取决于你想要达到的目标。
如果你想在多个列上加入两个表,你需要使用new {}
运营商:
First of all, please read my comment to the question.
The answer to the question: how to optimize linq query? - depends on what you're trying to achieve.
If you want to join both tables on multiple columns, you need to usenew{}
operator:
var rows1 = from bb in dt3.AsEnumerable()
join dd in newDt2.AsEnumerable() on
new {bb.Field<string>("Request_ID"), dd.Field<string>("Request_ID"}
equals
new { bb.Field<string>("Route_Header_ID"), dd.Field<string>("Route_Header_ID")}
select new {bb, dd};</string>
更多信息: c# - 如何在单个连接中的多个字段上进行LINQ连接 - Stack Overflow [ ^ ] br />
如果你想提供任何其他操作(左连接,除了等),请看这里: C#中的101个LINQ样本 [ ^ ]
对于lambda样式,i推荐这个网站: LINQ 101样本 - Lambda样式 [ ^ ]
请更具体一点下次提供更多详细信息。
More at: c# - How to do joins in LINQ on multiple fields in single join - Stack Overflow[^]
If you want to provide any other operation (left join, except, etc.), please take a look here: 101 LINQ Samples in C#[^]
For lambda style, i'd recommend this site: LINQ 101 Samples - Lambda Style[^]
Please, be more specific and provide more details next time.
这篇关于如何优化linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!