如何编写Linq to SQL查询,该查询转换为以下内容:
SELECT CAST(DATETEXT AS datetime) FROM mytable
答案 0 :(得分:1)
var dates = from row in mytable
select DateTime.Parse(row.DATETEXT);
DateTime.Parse
有方法重载,允许您指定格式。
答案 1 :(得分:-1)
var query = from c in mytable
select c;
然后你将使用它;
DateTime _value = (DateTime)query.SingleOrDefault().DATETEXT
但是如果你想用它那么多。这是一个例子;
NorthwindEntities _e = new NorthwindEntities();
public void poo() {
var query = from e in _e.Products
select DateTime.Parse(e.DateText);
}