将查询转换为Lambda表达式

时间:2012-11-15 05:12:47

标签: c# lambda

在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();

enter image description here

2 个答案:

答案 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();