8
I have a model where all fields are string
.
I want to convert to DateTime
and Double
For that 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; }
}
and 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.
on the line: var DateQuery = db.servidorIIS.ToList().Select(o => new CPUStats
I do this conversion because then I make a query by date order:
var CPU = DateQuery.OrderByDescending(x => x.Data).Take(5).ToList();
In MSSQL this date field is string
is with the following data:
03/16/2016 04:09:16.936
so I did it right, what was missing was specifying the date format that Inq is not understanding? the en-US standard should not be default?
– Dorathoto
LINQ has nothing to do with it. But the format was missing. O default depends on the computer where it is running.
– Maniero