I have a database where the columns are int datatypes. The column int-values corresponds to seconds since 1980-01-01 (MS-DOS timestamp).
Is it possible to convert these int-values using Entity Framework? 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):
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.
I would put an additional property on the entity class which gets the original int-value through a converter:
public partial class MyEntity
{
public DateTime Date
{
get { return ConvertToDateTime(this.IntDate); }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With