以下数据源都假设为data
1.获取某列的不重复数据
List<int> ids = data.Select(t => t.ID).Distinct().ToList();
2.对list进行in查询
List<int> ids = new List<int>() { 1,2,3};
List<Entity> data = data.Where(tb => ids.Contains(tb.ID)).Select(tb => tb).ToList();
选择指定列
var data = data.Select(t=>new{ t.id,t.name});
转换成字典
var data = data.ToDictionary(key => key.ID, value => value.Name);
3.排序
OrderBy(s=>s.Name) 正序
OrderByDescending(s=>s.Name) 倒序
OrderBy(s=>s.Type).ThenBy(s => s.Name) 联合排序
OrderByDescending(s=>s.Type).ThenBy(s => s.Name) 联合排序
OrderBy(s=>s.Type).ThenByDescending(s => s.Name) 联合排序
OrderByDescending(s=>s.Type).ThenByDescending(s => s.Name) 联合排序
时间: 2024-10-15 10:55:06