先ToList() 到内存,然后在内存里ToString(“yy-MM-dd”)
var data = db.T_SamplePlot
.Where(d => d.PlotID == id)
Select(d => new {
d.PlotID,
d.LocationID,
d.InvestigationTime
})
.ToList()
.Select(d => new { d.PlotID, d.LocationID,
InvestigationTime = d.InvestigationTime == null ? null : d.InvestigationTime.Value.ToString("yyyy-MM-dd HH:mm"),//((DateTime)d.InvestigationTime).ToString("yyyy-MM-dd HH:mm"),
})
.FirstOrDefault();