"指定类型的成员'日期'不是在LINQ&QUOT的支持; [英] "The specified type member 'Date' is not supported in LINQ "

查看:133
本文介绍了"指定类型的成员'日期'不是在LINQ&QUOT的支持;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  _dbEntities.EmployeeAttendances.Where(X => x.DailyDate.Date.Equals(DateTime.Now.Date))。了ToList(); 




指定类型的成员'日期'不是在LINQ支持
实体,只有初始化,实体成员和实体导航
属性都支持。




我可以如何做此得到员工的数据基础上,LINQ查询当前的日期?


解决方案

的EntityFramework 不能 DateTime.Date 转换为SQL。因此,它不能产生预期的SQL。相反的,你可以使用 EntityFunctions.TruncateTime()方法,如果你想获得日期部分只:

  _dbEntities.EmployeeAttendances 
。凡(X => EntityFunctions.TruncateTime(x.DailyDate)== DateTime.Now.Date )
.ToList();



附加信息:



EntityFunctions 方法被调用的规范函数。而这些是一组功能,这是由所有的实体框架提供商都支持。这些规范的功能将被转换为提供相应的数据源功能。 。规范功能是语言的核心外部访问功能的首选方法,因为它保留查询便携



您可以找到所有经典功能的 这里 和所有日期和时间规范函数< A HREF =htt​​ps://msdn.microsoft.com/en-us/library/bb738563(v=vs.110).aspx相对=nofollow> 这里


_dbEntities.EmployeeAttendances.Where(x => x.DailyDate.Date.Equals(DateTime.Now.Date)).ToList();

"The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

How can i do this get employees data on based on current date in linq query?

解决方案

EntityFramework cannot convert DateTime.Date to SQL. So, it fails to generate expected SQL. Instead of that you can use EntityFunctions.TruncateTime() method if you want to get Date part only:

 _dbEntities.EmployeeAttendances
            .Where(x => EntityFunctions.TruncateTime(x.DailyDate) == DateTime.Now.Date)
            .ToList();

Additional info:

EntityFunctions methods are called canonical functions. And these are a set of functions, which are supported by all Entity Framework providers. These canonical functions will be translated to the corresponding data source functionality for the provider. Canonical functions are the preferred way to access functionality outside the core language, because they keep the queries portable.

You can find all canonical functions here and all Date and Time Canonical Functions here.

这篇关于&QUOT;指定类型的成员'日期'不是在LINQ&QUOT的支持;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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