Where results1
is an IQuerable<myObject>
that works fine until you try and filter by date:
results1 = results1.Where(l => DbFunctions.DiffDays(FromDate, l.LeadDate) >= 0);
And then I get this error:
This function can only be invoked from LINQ to Entities
I've seen a few other threads here that get me close to an answer, like this one, but it's just different enough that I'm not sure how to reformulate this filter so that it doesn't try and do this in memory (which is why I think the error is happening?)
EDIT:
The query was too complex to get it working in Linq. I thought this would be the same, but maybe not?
var query1 = @"
SELECT
// columns that match the object 'myObject'
FROM
// a whole bunch of joins and left joins
ORDER BY
....";
var results1 = Context.DbContext.Database.SqlQuery<myObject>(query1).AsQueryable();
Can you use DateTime.Subtract
and TimeSpan.Days
?
results1 = results1.Where(l => FromDate.Subtract(l.LeadDate).Days >= 0).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With