在mysql中,
select distinct(trim(containerType)) from productIn where containerType <> '' group by containerNo
如何使用Lambda创建表达式查询?
例)
List<string> containerTypes = new List<string>();
containerTypes = productInRepository.GroupBy(x=> x.containerNo).Select(?????).ToList();
答案 0 :(得分:1)
List<string> containerTypes = productInRepository
.Where(x => x.containerType != string.Empty)
.GroupBy(x=> x.containerNo)
.Select(x => x.containerType.Trim())
.ToList();
答案 1 :(得分:1)
我认为不在结果选择中的groupby字段意味着与该字段的顺序相同。
List<string> containerTypes = productInRepository
.Where(x => x.containerType != string.Empty)
.OrderBy(x => x.containerNo)
.Select(x => x.containerType.Trim())
.Distinct();