我創建像比較兩個字符串一個簡單的搜索:我怎麼能比較和SEACH字符串和日期時間C#
articles = _service.ArticleRepository.GetAll(id, new Expression<Func<Article, bool>>[] { x => x.Title.Contains(searchWord) }, a => a.ArticleCategory);
和工程罰款;但我想在日期時間(日期)搜索,我寫不同的代碼:
articles = _service.ArticleRepository.GetAll(id, new Expression<Func<Article, bool>>[] { x => x.InsertDate ==DateTime.Parse(searchWord) }, a => a.ArticleCategory);
或
articles = _service.ArticleRepository.GetAll(id, new Expression<Func<Article, bool>>[] { x => x.InsertDate.ToString("yyyyMMdd").Contains(searchWord) }, a => a.ArticleCategory);
給我一個錯誤:
LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression.
From this line int count = _db.Count();
我怎麼可以做一些字符串之間的比較和日期作爲一個字符串輸入日期(以不同的格式,如:2017/8/5或05/05/2017或2017-8-5或...)或甚至輸入一個數字(搜索所有日期有一個數字)?