LINQ to Entity Framework 4.0。 SQL Server。實體4.0 Casting Value As DateTime
我想返回對象的列表,並在數據庫中的一列是varchar(255)幷包含日期。我試圖將這個值轉換爲datetime,但是我還沒有找到解決方案。
例子:
List<MyObject> objects = (from c in context.my_table
where c.field_id == 10
select new MyObject()
{
MyDate = c.value // This is varchar, want it to be datetime
}).ToList();
這是不可能的?
更新。這是LINQ to Entity。當試圖轉換爲DateTime我得到:
LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression.
我得到這個錯誤:LINQ到實體無法識別方法「System.DateTime的解析(System.String)」的方法,而且這種方法不能翻譯成商店表達。 – GregInWI2 2010-12-03 19:38:34