Anyone know how to query for a specific date within entity framework ? I tried following code, but it gives me NotSupportedException.
var deposit = (from tempDeposit in entities.Deposit where !tempDeposit.IsApproved && tempDeposit.CreatedDate.Date == DateTime.Today select tempDeposit).FirstOrDefault();
I also tried following code but still gave me NotSupportedException.
var deposit = (from tempDeposit in entities.Deposit where !tempDeposit.IsApproved && tempDeposit.CreatedDate.ToFullString() == DateTime.Today.ToFullString() select tempDeposit).FirstOrDefault();
ToFullString() is an extension method
public static string ToFullString(this DateTime date){ return date.ToString('yyyyMMdd'); }
Please help.
Try this:
Since you can’t use the .Date property of a DateTime column, since that would have to be written in SQL with a range of converts, casts, truncates, etc. then you need to compare the whole DateTime value, date and time both, to a value, and thus you need to compare to a range.
Edit Changed to reflect that .AddDays isn’t supported.