Linq toEntity 查询中的日期时间操作
运行此代码:
public bool CheckTime(DateTime date, int UserID, int TotalTimeMin)
{
using (var context = new myDB())
{
var assginments = from c in context.Assignments.Where(x=>(x.AssignmentDateTime < date && x.AssignmentDateTime.Value.AddMinutes(TotalTimeMin) > date) ||
(x.AssignmentDateTime < date.AddMinutes(TotalTimeMin))) select c;
if(assginments != null) return false;
else return true;
}
}
我收到此错误。
LINQ to Entities does not recognize the method 'System.DateTime AddMinutes(Double)' method, and this method cannot be translated into a store expression.
TotalTimeMin 是 int。我不确定是什么原因造成的: 分配日期时间是日期时间吗?也许这就是问题所在?
running this code:
public bool CheckTime(DateTime date, int UserID, int TotalTimeMin)
{
using (var context = new myDB())
{
var assginments = from c in context.Assignments.Where(x=>(x.AssignmentDateTime < date && x.AssignmentDateTime.Value.AddMinutes(TotalTimeMin) > date) ||
(x.AssignmentDateTime < date.AddMinutes(TotalTimeMin))) select c;
if(assginments != null) return false;
else return true;
}
}
I get this error.
LINQ to Entities does not recognize the method 'System.DateTime AddMinutes(Double)' method, and this method cannot be translated into a store expression.
TotalTimeMin is int. I am not sure what cause this:
AssignmentDateTime is DateTime? and maybe this is the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 EntityFunctions.AddMinutes(需要 EF 4):
请注意,分配将永远为空(但它可能为空 - 测试
作业.Any()
)。Use
EntityFunctions.AddMinutes
(requires EF 4):Note that
assignments
will never be null (but it might be empty -- testassignments.Any()
).