Linq to Entities SqlFunctions.DateDiff not supported
c#, entity-framework-4.1, linq, linq-to-entities
Solution
Maybe you could try using EntityFunctions rather than SqlFunctions.
Problem
I have the following code ``` DateTime now = DateTime.UtcNow; var allItemsOver64 = _inventoryContext.Items.Where(i => (SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) >= 65); IQueryable<Item> items65To69 = allItemsOver64.Where(i => (SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) >= 65 && (SqlFunctions.DateDiff("dd", i.PrimaryInsured.DoB, now) / 365.0) <= 69); ``` But when I try and use allItemsOver64 thus Items65To69.Count() I get this error The expression ((((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) >= 65) And ((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) >= 65)) And ((Convert(DateDiff("dd", [10007].PrimaryInsured.DoB, 26/04/2012 15:03:09)) / 365) <= 69)) is not supported. What am I doing wrong?