2

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

2
  • It's been a while since I've done MySql, but is your SQL even legal? A select on a field not included in the group by? Commented Nov 15, 2012 at 5:15
  • I just test it, yes it works Commented Nov 15, 2012 at 5:23

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.