List<Trademark_Category_Asso> list_Group = db.Select<Trademark_Category_Asso>(exp).Skip((operation.Page - 1) * operation.Limit).Take(operation.Limit).ToList(); List<Trademark_Category_AssoParams> list1 = new List<Trademark_Category_AssoParams>(); for (int i = 0; i < list_Group.Count; i++) { for (int j = (i + 1); j < list_Group.Count; j++) { if (list_Group[j].ProductModelId == list_Group[i].ProductModelId && list_Group[j].CategoryId == list_Group[i].CategoryId) { list_Group.RemoveAt(j);//去除相同的项 i = 0;//从新开始去重,如果数组内有大量重复的项,仅一次去重不能解决问题。这样的用法会使效率慢1/3 j = 0; } } } foreach (Trademark_Category_Asso a in list_Group) { Trademark_Category_AssoParams param = new Trademark_Category_AssoParams(); TrademarkCP cp = db.Select<TrademarkCP>(s => s.CPTrademarkId == a.TrademarkCPId).FirstOrDefault(); PartCP1 pcp = db.Select<PartCP1>(s => s.CPNameId == a.CategoryId).FirstOrDefault(); PartCP cp1 = db.Select<PartCP>(s => s.CPTypeId == pcp.CPTypeID).FirstOrDefault(); ProductModel pm = db.Select<ProductModel>(s => s.ModelId == a.ProductModelId).FirstOrDefault(); param.BigCategoryId = cp1.CPTypeId; param.BigCategoryName = cp1.PartTypeName; param.CategoryId = pcp.CPNameId; param.CategoryName = pcp.PartName; param.ProductModelId = pm.ModelId; param.ProductModelName =pm.ModelName; param.TCAssoId = a.TCAssoId; param.TCNote = a.TCNote; param.TrademarkCPId = cp.CPTrademarkId; param.TrademarkCPName = cp.CPTrademarkName; list1.Add(param); }
主要代码:
for (int i = 0; i < list_Group.Count; i++) { for (int j = (i + 1); j < list_Group.Count; j++) { if (list_Group[j].ProductModelId == list_Group[i].ProductModelId && list_Group[j].CategoryId == list_Group[i].CategoryId) { list_Group.RemoveAt(j);//去除相同的项 i = 0;//从新开始去重,如果数组内有大量重复的项,仅一次去重不能解决问题。这样的用法会使效率慢1/3 j = 0; } } }
List Group
var t = db.Select<Trademark_Category_Asso>().GroupBy(s => new { s.CategoryId, s.ProductModelId }); foreach (var t1 in t) { Console.WriteLine(t1.Key.CategoryId + " " + t1.Key.ProductModelId); }