如何仿效此SQL查詢:如何獲得以下輸出Linq中
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
其中給出:
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);
:
要使用此查詢給出相同的輸出
我無法修改我的選擇列表和加入條件 - 當我嘗試我得到Object reference not set to an instance of an object.
有2臺dtSplitDates
和dtSplitDates2
這是表dtSplitDates
現在的外觀和dtSplitDates2
是它的克隆: