我是ASP.NET新手。我在會議表中有date_meeting(日期時間)列。我想從表中加載數據,這是date_meeting的日期是今天。 我嘗試的任何變化:在ASP.NET mvc 3中比較日期和日期時間?
List<Meeting> meetings = db.Meetings.Where(x => x.date_meeting == Convert.ToDateTime(DateTime.Now.ToString("dd.mm.yyyy")).Date && x.langId == lang).ToList();
錯誤:
LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression.
我需要這種邏輯。
List<Meeting> meetings = db.Meetings.Where(x => x.date_meeting.ToString("dd.mm.yyyy") == DateTime.Now.ToString("dd.mm.yyyy") && x.langId == lang).ToList();
錯誤:底層提供程序在打開時失敗。 – 2014-09-10 12:34:59
http://www.codeproject.com/Articles/499987/LINQ-query-to-compare-only-date-part-of-DateTime試試這個 – 2014-09-10 12:39:12
成功:'列表 meeting = db.Meetings.Where(x = > x.date_meeting.Value.Day == DateTime.Now.Day && x.date_meeting.Value.Month == DateTime.Now.Month && x.date_meeting.Value.Year == DateTime.Now.Year && x。 langId == lang).ToList();'感謝鏈接@meajaygoel –
2014-09-10 12:55:32