0

I am having trouble translating following query to EF:

SELECT DISTINCT
[CompanyId]
,[CompanyNumber]
,[ReturnsLastMadeUpDate]
FROM [CHX].[dbo].[CompanyDetailsDailyDump]
WHERE [InsertDate] BETWEEN '2012-12-19' and '2013-01-20'
ORDER BY [ReturnsLastMadeUpDate] DESC

The main issue is with the Distinct(). How can I select above three specific columns to be compared for distinct rather than all the columns. Regards

2
  • 1
    Did you google it? .Distinct() would appear to be the answer. Why am I doing you google searches? Commented Jan 23, 2013 at 11:44
  • Yeah, but the distinct will compare all available columns rather than only three. If only specific columns are select able, this could also solve the problem. Commented Jan 23, 2013 at 11:48

1 Answer 1

1

You just need to apply Distinct after all other operations. I.e.:

CompanyDetailsDaily
    .Where(x => x.InsertDate < DateTime.Parse('2013-01-20') && 
            x.InsertDate > DateTime.Parse('2012-12-19'))
    .OrderBy(x => x.ReturnsLastMadeUpDate)
    .Select(x => new{x.CompanyID,x.CompanyNumber,x.ReturnsLastMadeUpDate})
    .Distinct();

Be careful with the date inclusion (one of the >/< symbols may need to be replaced with =>/<=)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank You very much, saved the day.
You're welcome! And welcome to Stack Overflow. Don't forget to accept and/or upvote answers to questions you've liked.

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.