score:2

Accepted answer

You have to filter between a start and end date if you want to make use of whatever indexes you might have on DepositDate. If you do not care about that there are Canonical Date Functions you can use to strip the time from the database value.

DateTime today = DateTime.Today;
DateTime tomorrow = today.AddDays(1);

var deposit = (from u in db.Deposit
               where u.DepositDate >= today && u.DepositDate < tomorrow
               select u).ToList();

Or as a lambda

var deposits = db.Deposit
                .Where(u => u.DepositDate >= today && u.DepositDate < tomorrow)
                .ToList();

As a side note and also a matter of opinion it generally recommended to pluralize DbSet<T> properties on your DbContext (like db.Deposits). The same goes for your variable deposit as it will be of type List<Deposit> which is a collection (the 2nd code sample I changed it).


Related Articles