问题描述
results1
是IQuerable<myObject>
的地方,在您尝试按日期进行过滤之前,它仍然可以正常工作
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);
然后我得到这个错误:
我在这里看到了其他一些线索,使我很接近答案,,但是它只是足够不同,以至于我不确定如何重新构造此过滤器,以便它不会尝试在内存中执行此操作(这就是为什么我认为正在发生错误?)
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?)
查询过于复杂,无法在Linq中运行.我以为会是一样的,但也许不是吗?
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();
推荐答案
可以使用DateTime.Subtract
和TimeSpan.Days
吗?
results1 = results1.Where(l => FromDate.Subtract(l.LeadDate).Days >= 0).ToList();
这篇关于DbFunctions.DiffDays()结果:此函数只能从LINQ到Entities调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!