DbArithmeticExpression参数必须具有数字通用类型 [英] DbArithmeticExpression arguments must have a numeric common type
本文介绍了DbArithmeticExpression参数必须具有数字通用类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
TimeSpan time24 = new TimeSpan(24, 0, 0);
TimeSpan time18 = new TimeSpan(18, 0, 0);
// first get today's sleeping hours
List<Model.Sleep> sleeps = context.Sleeps.Where(
o => (clientDateTime - o.ClientDateTimeStamp < time24) &&
o.ClientDateTimeStamp.TimeOfDay > time18 &&
clientDateTime.TimeOfDay < time18 &&
o.UserID == userid).ToList();
此Linq表达式抛出此异常:
This Linq expression throws this exception:
DbArithmeticExpression arguments must have a numeric common type.
请帮助!
推荐答案
实体框架不支持使用 DateTime
的算术。您必须使用 DbFunctions *。所以,对于你的陈述的第一部分,例如:
Arithmetic with DateTime
is not supported in Entity Framework. You have to use DbFunctions*. So, for the first part of your statement, something like:
var sleeps = context.Sleeps(o =>
DbFunctions.DiffHours(o.ClientDateTimeStamp, clientDateTime) < 24);
请注意, DiffHours
方法接受 Nullable< DateTime>
。
* EntityFunctions
。
这篇关于DbArithmeticExpression参数必须具有数字通用类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文