Expert wanna be
Expert wanna be

Reputation: 10624

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

enter image description here

Upvotes: 2

Views: 172

Answers (2)

Dima
Dima

Reputation: 6741

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

Upvotes: 1

Spencer Ruport
Spencer Ruport

Reputation: 35107

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

Upvotes: 1

Related Questions