开发者

How do I write a Linq to SQL query with a cast?

开发者 https://www.devze.com 2023-02-22 21:56 出处:网络
How do i write开发者_开发技巧 a Linq to SQL query that translates into the following: SELECT CAST(DATETEXT AS datetime) FROM mytable

How do i write开发者_开发技巧 a Linq to SQL query that translates into the following:

SELECT CAST(DATETEXT AS datetime) FROM mytable


var dates = from row in mytable
            select DateTime.Parse(row.DATETEXT);

There are method overloads for DateTime.Parse that allow you to specify a format.


actually, you won't be needing that. just parse it as datatime when you will use the field value. here is an exaple;

var query = from c in mytable
            select c;

then when you will use it;

DateTime _value = (DateTime)query.SingleOrDefault().DATETEXT

but if you wanna use it so much. here is an example;

NorthwindEntities _e = new NorthwindEntities();

public void poo() {

    var query = from e in _e.Products
                select DateTime.Parse(e.DateText);

}
0

精彩评论

暂无评论...
验证码 换一张
取 消