Convert timestamp to DateTime using Entity Framework

I have a database where the columns are int datatypes. The column values ​​correspond to seconds from 1980-01-01 (MS-DOS timestamp).

Is it possible to convert these int values ​​using Entity Framework? If this is not so? Conversion must be effective.

I tried the following SQL in my controller, but I get 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.

+4
source share
1 answer

I would add an additional property to the entity class, which receives the initial intrinsic value through the converter:

 public partial class MyEntity { public DateTime Date { get { return ConvertToDateTime(this.IntDate); } } } 
+1
source

All Articles