Using the 'LIKE' operator inside a Lambda Expression

Topics: General
Feb 1, 2013 at 11:53 AM
In my Entity (Sale) has a type of DateTime column Date.

I used following lambda expression to get the latest TrNo from that table. But always it gives me Null. Because it also compares the Time part of the column. Actually I wanted to compare the Date part of the column.
db.Sales.OrderByDescending(O => O.Date).Where(O => O.Date == DateTime.Now ).Select(O => O.TrNo).FirstOrDefault();
Please help me to get the build the right code. (My db is MySQL)

Feb 1, 2013 at 5:26 PM
You need to use EDM TruncateTime canonical function. Take a look at this thread on stackoverflow: Note that in EF6 functions were moved to DbFunctions class.
Feb 1, 2013 at 6:13 PM
Error: "FUNCTION <project namespace>.TruncateTime does not exist"
Feb 1, 2013 at 6:41 PM
How did you use it?
Feb 1, 2013 at 6:44 PM
db.Sales.OrderByDescending(O => O.Date).Where(O => O.Date == EntityFunctions.TruncateTime(DateTime.Now)).Select(O => O.TrNo).FirstOrDefault();
Feb 1, 2013 at 8:32 PM
This might be provider specific. From what I can see DevArt MySql provider has TruncateTime function ( starting from v4). Do you mind showing the stack trace?