简体   繁体   中英

Converting query to Lambda Expression

In mysql,

select distinct(trim(containerType)) from productIn where containerType <> '' group by containerNo

How can I make expression that query using Lambda?

Ex)

List<string> containerTypes = new List<string>();
containerTypes = productInRepository.GroupBy(x=> x.containerNo).Select(?????).ToList();

在此处输入图片说明

List<string> containerTypes = productInRepository
    .Where(x => x.containerType != string.Empty)
    .GroupBy(x=> x.containerNo)
    .Select(x => x.containerType.Trim())
    .ToList();

I think groupby field which is not in result select means the same as orderby this field.

List<string> containerTypes = productInRepository
                .Where(x => x.containerType != string.Empty)
                .OrderBy(x => x.containerNo)
                .Select(x => x.containerType.Trim())
                .Distinct();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM