本文介绍了如何获得Linq中下面的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何模拟此SQL查询:
How to emulate this Sql query:
Select A.FID, A.SLNO, A.Date as FromDate, A1.Date ToDate
From #Test A
Inner Join #Test A1 On A.FID = A1.FID And A1.SLNO = A.SLNO + 1
其中给出:
要放弃使用此查询相同的输出:
To give the same output using this query:
var results2 = from table1 in dtSplitDates.AsEnumerable()
join table2 in dtSplitDates.AsEnumerable() on new { FID = table1.Field<int>("FID"), SLNO = table1.Field<int>("SLNO")} equals new { FID = table2.Field<int>("FID"), SLNO = table2.Field<int>("SLNO") } into lj
from r in lj.DefaultIfEmpty()
select dtSplitDates2.LoadDataRow(new object[]
{
r["FID"],
r["SLNO"],
r == null ? string.Empty : r["Dates"]
}, false);
我无法改变我的选择列表和连接条件 - 当我尝试,我得到对象引用未设置到对象的实例。
有2个表 dtSplitDates
和 dtSplitDates2
这是表 dtSplitDates
现在的外观和 dtSplitDates2
是它的克隆:
This is how the table dtSplitDates
looks now and dtSplitDates2
is its clone:
推荐答案
什么是dtSplitDates2?
What is dtSplitDates2 ?
可以请你分享你的表格内容。
Can you please share your table contents.
但我明白,我宁愿这个解决方案
But what I understood, I would prefer this solution
var results2 = from table1 in dt1.AsEnumerable()
join table2 in dt2.AsEnumerable() on new { FID = table1.Field<int>("FID"), SLNO = table1.Field<int>("SLNO") } equals new { FID = table2.Field<int>("FID"), SLNO = table2.Field<int>("SLNO") } into lj
from r in lj.DefaultIfEmpty()
select new
{
FID = r["FID"],
SLNO = r["SLNO"],
Dates = r == null ? string.Empty : r["Date"]
};
这篇关于如何获得Linq中下面的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!