【发布时间】:2014-11-01 12:10:18
【问题描述】:
我有一个实体框架架构,如下所示。
Class Contact
{
string name;
DateTime creationDate;
}
and i've a string that is
string date="9/9/14 3:00:00 PM"
我正在执行以下查询
var q=from u in db.Contacts where u.creationDate.ToString==date select u;
但我面临以下错误
LINQ to Entities 无法识别方法“System.String ToString()”方法,并且该方法无法转换为存储表达式。
谁能告诉我如何比较 dateTime 和 string ?什么是可能的演员?
【问题讨论】:
-
将您的字符串解析为 DateTime 对象并在您的查询中使用它。
-
是的,我通过这个语句 DateTime temp=Convert.ToDateTime(date);但是现在查询没有返回任何结果。
标签: c# .net database entity-framework-4