我需要調用ToShortDateString在LINQ查詢起訴lambda表達式:如何在linq lambda表達式中使用ToShortDateString?
toRet.Notification = Repositories
.portalDb.portal_notifications.OrderByDescending(p => p.id)
.FirstOrDefault(p => p.date.ToShortDateString() == shortDateString);
,但我得到的錯誤:
An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method, and this method cannot be translated into a store expression.
我能做些什麼,考慮到我確實需要使用ToShortDateString()
?
謝謝。
這個線程可能有幫助:http://stackoverflow.com/questions/5370402/entity-framework-4-linq-how-to-convert-from-日期時間到字符串的查詢 –
此線程應該幫助: http://stackoverflow.com/questions/18233495/linq-to-entities-does-not-recognize-the-method-system-string- tostring-method –