2011-11-09 6 views
0

私は簡単な検索を実装しています。今は、文字列配列Splitの用語を使って投稿を検索できますが、日付も検索したいと思います。だから、私はdatetimeの配列を追加しました。私が抱えている問題は、datetimeのDate部分を検索し、Timeを無視するだけです。私が検索するたびに、私はd.Dateでエラーになります。Array 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はなく、date以外のものはすべて機能します。私がd.DateまたはEndDate.Dateを削除した場合、エラーはありませんが、希望する結果が得られません。 ありがとうございました。

編集1:

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

宣言は本当に愚かに見えるかもしれません。 Datifyは私が書いた関数で、DateTimeの配列を返します。これは、ローカル変数を見ながら段階的に進んだためです。

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

クエリは検索文字列です。

+3

あなたはDate'は 'どう思いますか? – Joe

+0

あなたはあなたのクエリが何をしていると思うか分けられますか?そして、私たちに 'split'と' Date'が何を助けるのかを宣言してください。つまり、2番目と3番目の「from」式は間違って見えます。 –

+0

日時:2010年10月10日12:36:....、日付は日時の2010年10月10日一部となります。 私はそれを分割し、それがどのように書くのかを試みます。あなたの – user1034489

答えて

1

は、時間の部分をトリミングするために、クラスEntityFunctionを使用してください。

using System.Data.Objects;

EntityFunctions.TruncateTime(終了日)