Reputation: 5869
I am trying to do the following in MySql but get a linq-to-entities exception that the functions are not supported. I've tried using SqlFunctions.DateAdd unsuccessfully. The only solution so far is to use a ToList() but that brings it all to the client which I don't love:
var expiredPolcies = context.ApiUsagePolicies
.Where(u => DateTime.UtcNow > u.UsagePolicyStart.AddSeconds(u.UsagePeriodSeconds));
Upvotes: 2
Views: 1283
Reputation: 43021
SqlFunctions is specific to Entity Framework and SQL Server.
SqlMethods is specific to Linq to SQL and SQL Server.
If there's an equivalent set of methods for MySql then you could use that.
Alternatively try rewriting your query so that there are no local methods involved. Try something like:
var expiredPolcies = context.ApiUsagePolicies
.Where(u =>
(DateTime.UtcNow - u.UsagePolicyStart).TotalSeconds > u.UsagePeriodSeconds);
It all depends on what functions your Linq provider supports.
Upvotes: 1