I have a model where all fields are string
.
I want to convert to DateTime
and Double
For this I created a new model
public class CPUStats
{
public DateTime Data { get; set; }
public Double? Disco { get; set; }
public Double? CPU { get; set; }
public Double? RAM { get; set; }
}
I made this select:
var DateQuery = db.servidorSQL.ToList().Select(o => new CPUStats
{
Data = DateTime.Parse(o.Data),
CPU = Double.Parse(o.CPU),
RAM = Double.Parse(o.RAM),
Disco = Double.Parse(o.Disco)
});
But I get the error:
String was not recognized as a valid DateTime.
in line: var DateQuery = db.servidorIIS.ToList().Select(o => new CPUStats
I make this conversion because then I make a query in order of date:
var CPU = DateQuery.OrderByDescending(x => x.Data).Take(5).ToList();
In MSSQL this date field that is string
has the following data:
03/16/2016 04: 09: 16.936