Count in Linq to Sql

69
Views
1
Answers

I want to return a count of new orders since a specific date.

SELECT COUNT(OrderId)
FROM
Orders
where dateordered > @date

How to do this in Linq to Sql?

edit | flag
William Patrick
Asked on: Jun 16, 2011 at 11:12PM

1 Answers

29
7
29

You can go two ways

var count = (from u in dbcontext.Orders
where u.dateordered > date select u).Count();

or

var count = dbcontext.Orders
.Where( x => x.dateordered > date).Count();

Cheers!!

edit | flag
Gokul A
Answered on: Jun 16, 2011 at 11:14PM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags