1.Linq中自带的计算方法:Sql.
。
2.GroupBy 用法
OcSheetNameInfo = OcFlowCheckTableNameConfig .GroupBy(flowBase => flowBase.FunctionTableName) .Select(S => new FlowCheckTableNameConfig { FunctionTableName = S.Key }).ToObservableCollection();
var mult = OcItemsTemp.GroupBy(g => new { g.MaterialID, g.TargetObjectID, }).Where(w => w.Count() > 1).ToList();
3.Dictonary
从字典(DicRoleForScope)中查询对应(role)的值再赋值给其他变量( DicSelectedRoleForScope) Dictionary<string, object> dic = DicRoleForScope.Where(s => s.Value.ToString().Contains(role)). Select(q => new { q.Key, q.Value }). ToList().AsEnumerable().ToDictionary(d => d.Key, d => (object)d.Value); // where对比中使用Contains KeyValuePair<string, object> kvp = dic.FirstOrDefault(); if (kvp.Key != null && kvp.Value != null) //注意判断为空否 { DicSelectedRoleForScope.Add(kvp.Key, kvp.Value); //Dictionary只能以键值对的形式添加 }
4.获取ID数组
int[] ids = entityList.Select(v => v.ID).ToArray();
5.汇总
OcOutStock.Sum(t => t.Amount).ToDecimal();