Vitaliy Vitaliy - 1 year ago 111
C# Question

get items from db between two dates: Exception thrown: 'System.NotSupportedException'

Trying to get items from db but getting System.NotSupportedException, found how to avoid but to me it doesn't help. Any ideas to how I can avoid this exception?

return await DbContext.Members.Where(
x => x.ClientId == criteria.ClientId
&& DbFunctions.TruncateTime(x.CreatedOn).Value.Date
>= criteria.StartDate.Value.Date
&& DbFunctions.TruncateTime(x.CreatedOn).Value.Date
<= criteria.EndDate.Value.Date

Answer Source

DbFunctions.TruncateTime truncates the time from the date, so there is no need to use .Value.Date, which is what is causing the exception.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download