DbArithmeticExpression参数必须具有数字公共类型。 [英] DbArithmeticExpression arguments must have a numeric common type.

查看:72
本文介绍了DbArithmeticExpression参数必须具有数字公共类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DbArithmeticExpression参数必须具有数字公共类型。

 canberraTimetable =(来自db.ShuttleTimeTables中的r 
其中r.TimeTypeId == 5&&(DateTime.Today。 Date + r.Time)> =(DateTime.Today.Date + time_15)
select r.Time)。ToList()
.Select(x => new SelectListItem()
{
Text = x.Value.ToString(@hh\:mm),
Value = x.Value.ToString(@hh\:mm)
}) .Take(3)。ToList();





如果我没有DateTime.Today.Date添加到r.Time那么就不会有问题了。

但是当time_15 = 23:59时,那么会选择8:00供用户使用,我不会这样。所以我将DateTime.Today.Date添加到它只在同一天进行箭头比较。

解决方案

 canberraTimetable = db.ShuttleTimeTables.Where (r => r.TimeTypeId ==  5 )。ToList()
.Where(r = > ; (DateTime.Today.Date + r.Time)> =(DateTime.Today.Date + time_15))
.Select( x = new SelectListItem()
{
Text = x.Time.Value.ToString( @ hh \:mm),
Value = x.Time.Value.ToString( @ hh \:mm
})。取( 3 )ToList();


DbArithmeticExpression arguments must have a numeric common type.

canberraTimetable = (from r in db.ShuttleTimeTables
                                                 where r.TimeTypeId == 5 && (DateTime.Today.Date + r.Time ) >= (DateTime.Today.Date + time_15)
                                                 select r.Time).ToList()
                                            .Select(x => new SelectListItem()
                                            {
                                                Text = x.Value.ToString(@"hh\:mm"),
                                                Value = x.Value.ToString(@"hh\:mm")
                                            }).Take(3).ToList();



if I don't have DateTime.Today.Date add to the r.Time then won't have problems.
But it when the time_15 = 23:59, then will select the 8:00 available to the user, I don't won't this. So I add DateTime.Today.Date to it only arrow compare at the same day.

解决方案

canberraTimetable = db.ShuttleTimeTables.Where(r=>r.TimeTypeId == 5).ToList()
.Where(r=>(DateTime.Today.Date + r.Time ) >= (DateTime.Today.Date + time_15))
.Select(x=  new SelectListItem()
            {
                Text = x.Time.Value.ToString(@"hh\:mm"),
                Value = x.Time.Value.ToString(@"hh\:mm")
            }).Take(3).ToList();


这篇关于DbArithmeticExpression参数必须具有数字公共类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆