【发布时间】:2015-09-16 06:46:02
【问题描述】:
我一直在尝试明智地将表数据 Date 分组,而忽略 time 部分。因为我需要数据源中的count 日期明智的编号。对于这一切,我尝试了很多选择,但都失败了。
我的第一次尝试
var data1 = from p in context.qry_view_record
where p.INT_ITEM_ID == 1
group p by p.DAT_VIEW_START.Date into g
select new { ViewDate = g.Key, Count = g.Count() };
失败并出现异常The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
第二次尝试
我尝试使用EntityFunctions 类将查询修改为
var data1 = from p in context.qry_view_record
where p.INT_ITEM_ID == 1
group p by EntityFunctions.TruncateTime(p.DAT_VIEW_START) into g
select new { ViewDate = g.Key, Count = g.Count() };
失败并出现异常FUNCTION Mynamespace.TruncateTime does not exist
第三次尝试
我尝试创建一个User defined MySql Function and stored procedure 来截断时间部分并将过程导入为FunctionImport
var data1 = from p in context.qry_view_record
where p.INT_ITEM_ID == 1
group p by context.sp_getDate(p.DAT_VIEW_START) into g
select new { ViewDate = g.Key, Count = g.Count() };
失败并出现异常LINQ to Entities does not recognize the method 'System.Data.Objects.ObjectResult1[System.Nullable1[System.DateTime]] sp_getDate(System.Nullable1[System.DateTime]) method, and this method cannot be translated into a store expression.
请提出任何解决方法..
【问题讨论】:
标签: c# mysql asp.net entity-framework-5 linq-to-mysql