Linq-to-Entities:格式选择查询表达式中的日期 [英] Linq-to-Entities: Format Date in select query expression
本文介绍了Linq-to-Entities:格式选择查询表达式中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
nonBusinessDays =( from ac in db.AdminCalendar
其中ac.DateTimeValue> = calendarStartDate&& ac.DateTimeValue< = calendarEndDate&& ac.IsBusinessDay == false
select ac.MonthValue +/ + ac.DayOfMonth +/+ ac.FullYear).ToList();
但是,我得到以下错误消息:
无法投射类型系统.Nullable`1'键入'System.Object'LINQ to Entities只支持转换Entity Data Model原始类型。
除了迭代之外,还有什么办法吗通过结果集?
谢谢!
Abe
解决方案
我发现一个解决方法:
nonBusinessDays =(from $ in
(from ac in db.AdminCalendar
where ac.DateTimeValue> = calendarStartDate&& ac.DateTimeValue< = calendarEndDate& ;& ac.IsBusinessDay == false
select ac.DateTimeValue).ToList()
select string.Format({0:M / d / yyyy},dt))。ToList() ;
I am trying to get a formatted date string directly from a LINQ-to-Entities query expression.
nonBusinessDays = (from ac in db.AdminCalendar
where ac.DateTimeValue >= calendarStartDate && ac.DateTimeValue <= calendarEndDate && ac.IsBusinessDay == false
select ac.MonthValue + "/" + ac.DayOfMonth + "/" + ac.FullYear).ToList();
But, I get the folloinw error message: "Unable to cast the type 'System.Nullable`1' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types."
Is there any way to do this besides iterating through the result set? Thanks! Abe
解决方案
I found one workaround:
nonBusinessDays = (from dt in
(from ac in db.AdminCalendar
where ac.DateTimeValue >= calendarStartDate && ac.DateTimeValue <= calendarEndDate && ac.IsBusinessDay == false
select ac.DateTimeValue).ToList()
select string.Format("{0:M/d/yyyy}", dt)).ToList();
这篇关于Linq-to-Entities:格式选择查询表达式中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文