实体4.0铸造值作为DateTime [英] Entity 4.0 Casting Value As DateTime
本文介绍了实体4.0铸造值作为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
LINQ to Entity Framework 4.0。 SQL Server。
我试图返回一个对象列表,数据库中的一个列是varchar(255)并包含日期。我试图将值转换为datetime,但我还没有找到解决方案。
示例:
List< MyObject> objects =(from c在context.my_table
其中c.field_id == 10
select new MyObject()
{
MyDate = c.value //这是varchar, it to be datetime
})。ToList();这是不可能的吗?
更新:
。这是LINQ to Entity。当尝试转换为DateTime时,我得到: LINQ to Entities不能识别方法System.DateTime ToDateTime )'方法,并且此方法不能转换为store表达式。
解决方案答案是目前不可能与Entity Framework。使用LINQ本身,只是不支持Entity Framework。
LINQ to Entity Framework 4.0. SQL Server.
I'm trying to return a list of objects and one of the columns in the database is varchar(255) and contains dates. I'm trying to cast the value to datetime, but I haven't found the solution to that yet.
Example:
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();
Is this not possible?
Update. This is LINQ to Entity. When trying to convert to DateTime I get:
LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression.
解决方案 The answer is it's not currently possible with Entity Framework. With LINQ itself it is, just not supported with Entity Framework.
这篇关于实体4.0铸造值作为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文