我很难使用Linq Select为列表生成序列号。
我尝试使用普通变量,然后在内部将其递增,但无法正常工作。
var grouped = (from x in jOMACDetails
group x by new { x.MAWorkCode, x.ConstructionNumber } into g
let f = g.First()
select new UtilityReceivingReportDetailEntity
{
DefaultAccountCode = string.IsNullOrWhiteSpace(f.AccountTitleCode) ? f.AccountTitleName.Trim() : f.AccountTitleCode.Trim(),
CompanyID = CurrentContext.CurrentCompanyID,
RRNumber = socnumber.Trim(),
RRSequenceNumber = (short)???, // <---- Here is the container the I need to be sequence
//...............
}).AsEnumerable();
有人可以帮我吗?提前致谢
您可以尝试Select()
通过自动合并元素的索引来重载,该重载将序列的每个元素投影为新形式:
var grouped = jOMACDetails.GroupBy(x => new { x.MAWorkCode, x.ConstructionNumber })
.Select(g => g.First())
.Select((r, index) => new UtilityReceivingReportDetailEntity
{
DefaultAccountCode = string.IsNullOrWhiteSpace(r.AccountTitleCode) ? r.AccountTitleName.Trim() : r.AccountTitleCode.Trim(),
CompanyID = CurrentContext.CurrentCompanyID,
RRNumber = socnumber.Trim(),
RRSequenceNumber = index
})
.AsEnumerable();
可悲的是,没有任何查询表达式使用该重载。所以,我用方法语法写了我的答案。但是,您可以根据需要.Select
在完成查询表达式后使用。但是,恕我直言,没有必要。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句