0
我正在实现一个简单的搜索。现在,我可以使用字符串数组Split中的术语来搜索帖子,但我也想搜索日期。所以,我添加了一个datetime数组。我遇到的问题是我只想搜索日期时间的日期部分,并忽略时间。无论何时我搜索,我都会在d.Date处收到错误消息。阵列DateTime.Date与Linq查询的兼容
IEnumerable<Post> posts = from p in post_repository.Posts
from s in split
from d in Date
where (p.Title.Contains(s) || p.ContactPhone.Contains(s) || p.Content.Contains(s) || p.Author.Contains(s) || p.ContactEmail.Contains(s)|| **p.EndDate.Date.Equals(d.Date)**) && p.Deleted == false && p.Publish == true
select p;
错误消息:
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
我一直停留在这一段时间,任何人都可以找出我做错了吗? 所有的日期都被初始化了,所以没有任何null和日期以外的其他东西都可以工作。如果我删除d.Date或EndDate.Date,没有错误,但我没有得到所需的结果。 在此先感谢。
编辑1:
string[] split = query.Split(breakpoints);
DateTime[] arrayOfDateTimes = Datify(split);
宣言似乎很愚蠢。 Datify是我写的一个函数,它返回一个正确工作的DateTime数组,因为我一步一步地看着局部变量。
private readonly char[] breakpoints = {'.', ',', ' ', ':', '\t' };
查询是搜索,它是一个字符串。
您认为Date是什么? – Joe
你能分裂你认为你的查询在做什么吗?给我们一个关于'split'和'Date'的声明也会有帮助。就像那样,那些第二个和第三个'from'表达式看起来是错误的。 –
DateTime:10/10/2010 12:36:....日期将是10/10/2010日期时间的一部分。 我会尽量分开它,并写出它的方式。 – user1034489