[英]Convert int timestamp to DateTime using Entity Framework
I have a database where the columns are int datatypes. 我有一个数据库,其中列是int数据类型。 The column int-values corresponds to seconds since 1980-01-01 (MS-DOS timestamp).
列int值对应于自1980-01-01以来的秒数(MS-DOS时间戳)。
Is it possible to convert these int-values using Entity Framework? 是否可以使用Entity Framework转换这些int值? If not that else to do?
如果不是那样做呢? The conversion needs to be efficient.
转换需要高效。
I have tried the following SQL in my controller but I receive a JSON error from the client (Fiddler output: JSON=-1): 我在我的控制器中尝试了以下SQL,但是我从客户端收到了一个JSON错误(Fiddler输出:JSON = -1):
public JsonResult GetData()
{
var model = entities.Database.ExecuteSqlCommand(
@"SELECT TOP 10
dateadd(S, [timestamp], '1980-01-01') [datetime_conv],
[value]
FROM [Data_2696415_20] AS tabel");
return Json(model, JsonRequestBehavior.AllowGet);
}
I am using Entity Framework version 6.1. 我正在使用Entity Framework 6.1版。
I would put an additional property on the entity class which gets the original int-value through a converter: 我会在实体类上放置一个额外的属性,它通过转换器获取原始的int值:
public partial class MyEntity
{
public DateTime Date
{
get { return ConvertToDateTime(this.IntDate); }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.