0

I need some help converting the SQL found below to an equivalent LINQ statement in C# assuming that I am using the EF also.

SELECT DISTINCT [ProductID],[NumberOfMixes]
  FROM [EPOS_DB].[dbo].[Combinations]
  WHERE NumberOfMixes != 1
  Group By ProductID, NumberOfMixes

The sql above is producing the correct number of results for me. I just want to wrap .Count().ToString method around a LINQ statement to produce a numeric valued stored in a string. That is all I need.

1
  • 2
    Why do you need the grouping if you already grab only distinct elements? Commented Nov 12, 2011 at 17:12

1 Answer 1

1

Something like this:

var count = context.Combinations
                   .Where( x=> x.NumberOfMixes!=1)
                   .Select( x=> new { x.ProductId, x.NumberOfMixes })
                   .Distinct()
                   .Count();
Sign up to request clarification or add additional context in comments.

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.