Error: DbArithmeticExpression arguments must have a numeric common type.

From time to time you need to filter data by difference between two dates. For instance, you wanna take a difference between date from a record and Today.

Standard request will fail with the statement like the following:

var r = from e in Entity where e.Date.Subtract(.Today) <= 5;

In  version 4 the new utility class has been introduced – EntityFunctions. With the method of this class you can rewrite the statement above like this:

var r = from e in Entity where EntityFunctions.DiffDays(.Today, e.Date) <= 5;

For someone who cannot use EntityFunctions for any reason there is a workaround. Long story short, you should compare the dates. The following changes might be done:

var maxDate = .Today.AddDays(5);
var r = ... where e.Date <= maxDate;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Post

%d bloggers like this: