【发布时间】:2021-12-21 23:10:50
【问题描述】:
我正在使用 lambda 表达式来访问具有数据类型的值,但问题是我的本地数据库上的 Time 数据类型为 Time(7) 并使用实体框架。在我的模型中,此数据类型定义为 DateTime。
我现在如何访问这种数据类型?
这是我的代码:
public List GetIncident_Details()
{
Entities incident = new Entities();
List result = new List();
var c_incident = incident.Incident_Template.Select(c => c).ToList();
if (c_incident != null && c_incident.Count() > 0)
{
foreach (var cData in c_incident)
{
Incident_DropDown model = new Incident_DropDown();
model.Title = cData.Title;
model.Description = cData.Description;
model.Date_Occurred = cData.Date_Occurred;
// How do I change this to have access?
// It's complaining about the data type object being set to a string?
model.Time = cData.Time;
model.Assignment_Group = cData.Assignment_Group;
model.Reported_CI = cData.Reported_CI;
result.Add(model);
}
}
return result;
}
public class Incident_DropDown
{
public string Title { get; set; }
public string Description { get; set; }
public string Date_Occurred { get; set; }
public DateTime Time { get; set; } // Time
public string Assignment_Group { get; set; }
public string Reported_CI { get; set; }
}
【问题讨论】:
-
如果
DateTime,您是否尝试使用TimeSpan? -
@AlexyRumnyantsev 没有
标签: c# asp.net-mvc entity-framework