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);
}
精彩评论