数组DateTime.日期兼容性与Linq查询

本文关键字:Linq 查询 兼容性 DateTime 日期 数组 | 更新日期: 2023-09-27 18:14:15

我正在实现一个简单的搜索。现在,我可以使用字符串数组Split中的术语搜索帖子,但我也想搜索日期。我添加了一个datetime数组。我遇到的问题是,我只想搜索datetime的日期部分,而忽略时间。每当我搜索时,我在d.Date处得到一个错误。

 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。日期,没有错误,但我没有得到想要的结果。提前感谢。

编辑1:

string[] split = query.Split(breakpoints);
DateTime[] arrayOfDateTimes = Datify(split);

宣言可能看起来真的很愚蠢。datatify是我写的一个函数,它返回一个DateTime数组,它可以正常工作,因为我一步一步地查看了局部变量。

private readonly char[] breakpoints = {'.', ',', ' ', ':', ''t' };

查询是搜索,它是一个字符串

数组DateTime.日期兼容性与Linq查询

使用类EntityFunction修剪时间部分

使用System.Data.Objects;

EntityFunctions.TruncateTime (EndDate)