我正在使用 linqtosql 并且在 linq 查询中,我尝试将日期时间类型列转换为像“dd-MM-yy”这样的字符串。
但是,我收到如下错误:
NotSupportedException: Method 'System.String ToString(System.String)' has no supported translation to SQL.
以下是我的 linq 查询:
from ffv in Flo_flowsheet_values
where ffv.Flowsheet_key == 2489
&& ffv.Variable_key == 70010558
&& ffv.Status == 'A'
&& ffv.Column_time >= DateTime.ParseExact("2010-06-13 00:00", "yyyy-MM-dd HH:mm", null)
&& ffv.Column_time <= DateTime.ParseExact("2010-06-13 22:59", "yyyy-MM-dd HH:mm", null)
select new {
ColumnTime = ffv.Column_time
,ColumnTimeForXCategory = ffv.Column_time.Value.ToString("dd-MM-yy") ***====> this statement invoke error***
,BTValue = Convert.ToDouble( ffv.Value) }
最佳答案
您可以使用 string.Format
比ToString()
方法来解决你的问题。
喜欢
ColumnTimeForXCategory = string.Format("{0:dd-MM-yy}",ffv.Column_time.Value)
关于linq-to-sql - 如何在 linqtosql 中将日期时间转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3052515/