0

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
    ).ToListAsync();
3

2 Answers 2

2

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

1

You can use EntityFunctions.TruncateTime :

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.