0

我想检索 transnett 和 obnett 的前一行值,以根据 StackHistoryID 更新当前行,那么上述查询是否有效?

var val = (from tn in db.tablename.ToList()
           where tn.ID.ToString() != currentID.ToString()
           orderby tn.TransactionDate descending
           group tn by tn.StackHistoryID into trans
           select new {
               transnett=trans.Select(t=>t.TransNett),
               obnett=trans.Select(t=>t.OBNett)
           }).FirstOrDefault();
4

1 回答 1

0

假设 TransactionDate 始终具有值并且设置正确,您的查询将返回最新行。那是你想要的还是你想要在那之前的那一行?

我认为您的查询看起来更好:

var rows = from tn in db.tablename
           where tn.ID != currentID
           orderby tn.TransactionDate descending
           group tn by tn.StackHistoryID into trans
           select new {transnett=trans.Select(t=>t.TransNett),obnett=trans.Select(t=>t.OBNett)});

var previousRow = rows.first();
于 2013-11-05T06:15:14.860 回答