1
Repository.Calls
    .Count(call => call.OutcomeActionDate.Value >= fourWeeksStartDate && 
                   call.OutcomeActionDate.Value < threeWeeksStartDate && 
                   call.UserId == user.UserId);

Above query gives me output 1 and the sql query:

select * 
from calls 
where userid = 1006 and
      outcomeactiondate >= '2013-08-19' and
      OutcomeActionDate < '2013-08-26'

gives me the output 15.

The output 15 is correct. I am not sure why is the linq query giving me incorrect value ? All the parameter values used in select query are same as passed in the linq query.

3
  • Have you used SQL Profiler to look at the SQL been generated by your code and checked it is what you expect? Commented Sep 17, 2013 at 21:16
  • What are the values of fourWeeksStartDate, threeWeeksStartDate, user.UserId. Most likely they are different from the ones in the sql query. Commented Sep 17, 2013 at 21:17
  • 1
    Date used must be in date format, some times we have time and we use the datetime that creates problems. Commented Sep 18, 2013 at 6:22

1 Answer 1

2

Try to use Date part of filtered dates:

Calls.Count(call => call.OutcomeActionDate.Value >= fourWeeksStartDate.Date &&
                    call.OutcomeActionDate.Value < threeWeeksStartDate.Date &&
                    call.UserId == user.UserId);
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.