List根据指定字段进行分组C#
2021-04-30 00:28
标签:pre set ble format each tostring add groupby row List根据指定字段进行分组C# 标签:pre set ble format each tostring add groupby row 原文地址:https://www.cnblogs.com/ReAiQingYi/p/14712994.html var sql = @"update [TABLE] WITH (ROWLOCK)
SET
匹配方式 = ‘{0}‘
where ID in({1})";
//lissqls 是你要分组的泛型集合
var GroupList = lissqls.GroupBy(x => x.MatchType).Select(x => new{ MatchType = x.Key, ItemIDLis = x.ToList() });
//存储更新语句
Liststring> update_bill_sql = new Liststring>();
foreach (var item in GroupList)
{
Listint> itemids = new Listint>();
foreach (var itemID in item.ItemIDLis)
{
itemids.Add(itemID.ItemID);
}
var newsql = string.Format(sql, item.MatchType, string.Join(",", Array.ConvertAllint, string>(itemids.ToArray(), delegate (int x) { return x.ToString(); })));
update_bill_sql.Add(newsql);
}