我想查询当前时间这个小时内的数据,请问该怎样查? 我这样写报错。
var list= db.user.Where( x =>x.UserName == userName && x.DateTime.ToString("yyyyMMddhhmmss") == DateTime.Now.ToString("yyyyMMddhhmmss")).ToList();
“System.NotSupportedException”类型的异常在 EntityFramework.SqlServer.dll 中发生,但未在用户代码中进行处理
其他信息: LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
var list= db.user.Where( x =>x.UserName == userName && x.DateTime >= DateTime.Now.AddHours(-1)).ToList();
还是报错
“System.NotSupportedException”类型的异常在 EntityFramework.SqlServer.dll 中发生,但未在用户代码中进行处理
其他信息: LINQ to Entities does not recognize the method 'System.DateTime AddHours(Double)' method, and this method cannot be translated into a store expression.
@正在缓冲: 改为这样:
var oneHourAgo = DateTime.Now.AddHours(-1); var list= db.user.Where( x =>x.UserName == userName && x.DateTime >= oneHourAgo).ToList();
var list= db.user.Where( x =>x.UserName == userName && x.DateTime > DateTime.Now.AddHours(-1)).ToList();
还是报错
“System.NotSupportedException”类型的异常在 EntityFramework.SqlServer.dll 中发生,但未在用户代码中进行处理
其他信息: LINQ to Entities does not recognize the method 'System.DateTime AddHours(Double)' method, and this method cannot be translated into a store expression.
@正在缓冲: 楼下已给出正确答案
大哥,你查的是当前这个小时内的数据吗?仔细检查一下你的代码勒