工作中EF遇到的问题

EF的条件中,无法用转格式,时间差作为条件,这时在EF6中,可以用

DbFunctions 这个类,例如:

db.NewsComments.Any( (entity.PostDate -  p.PostDate).TotalMinutes < 30 ); //本意是找到与该数据30分钟之内的数据,但是会报错

db.NewsComments.Any( DbFunctions.DiffMinutes(entity.PostDate, p.PostDate) < 30 ); //用DbFunctions就可以得到期望结果了

原文地址:https://www.cnblogs.com/dengshaojun/p/4313606.html