I send a SQL query and receive FOR JSON .
SqlCommand comm = new SqlCommand(@"select top (1000) Date,[open],high,low,[close] from dbo.[foo"] where date > @backDate and date <= @Date order by date FOR JSON AUTO", conn);
comm.Parameters.AddWithValue("@Date", _definition.dateFrom);
comm.Parameters.AddWithValue("@backDate", lowLimit);
string json = (string)comm.ExecuteScalar();
Debug.WriteLine(json);
/* this causes invalid deserialization */
CudaEngine.OHLC[] stream = JsonConvert.DeserializeObject<CudaEngine.OHLC[]>(json);
So the DateTimeOffset
in json result looks like this:
[{"Date":"2019-07-30T00:29:00Z","open":1.241829000000000e+004,"high":1.245195000000000e+004,
My ohcl struct have to be like this with date as long.
public struct OHLC
{
public long UTCdate;
public double open;
public double High;
public double Low;
public double Close;
}
How can I cast date directly from SQL statement to receive a .Net long either ticks or millisecond? How can I deserialize without the invalidCastException
?