LINQ to Entities不支持“Date”。只支持初始化器,实体成员和实体导航属性 [英] 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

查看:130
本文介绍了LINQ to Entities不支持“Date”。只支持初始化器,实体成员和实体导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下代码,并收到错误

I am trying to execute the following code and am receiving an error

public List<Log> GetLoggingData(DateTime LogDate, string title)
{
     var context = new LoggingEntities();
     var query = from t in context.Logs

           where t.Title == title 
           && t.Timestamp == LogDate

           select t;
     return query.ToList();
}

我收到的错误是指定的类型成员'Date' LINQ to Entities不支持,只支持初始化,实体成员和实体导航属性。我尝试过将每一个字符串转换成字符串的各种尝试,只是比较日期部分,但似乎没有得到正确的组合。非常感谢任何帮助。

The error I'm receiving is "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported." I have tried various attempts of casting everythign to a string, only comparing the date part, but can't seem to get the right combinaation. Any help is greatly appreciated.

推荐答案

不是最好的解决方案,但它的工作原理。由于各种原因,我现在必须使用.net 3.5,修改数据库将是困难的。无论如何,这里是一个解决方案:

Not the greatest solution, but it works. For a variety of reasons, I have to use .net 3.5 at this point and modifying the database would be difficult. Anyways, here is a solution that works:

            var query = from t in context.Logs
                      where t.Title == title 
                      && t.Timestamp.Day == LogDate.Day
                      && t.Timestamp.Month == LogDate.Month
                      && t.Timestamp.Year == LogDate.Year
                      select t;

不是最优雅的解决方案,但有效。

Not the most elegant solution, but it is effective.

这篇关于LINQ to Entities不支持“Date”。只支持初始化器,实体成员和实体导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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