我是实体框架的新手。我正在尝试使用 LINQ 查询和实体框架从数据库中检索数据。
IEnumerable<Gate> lstGate = from tbsite in dc.tblSites
select new Gate
{
CalledInAt = DateTime.Parse(tbsite.CalledInAt.ToString(), new CultureInfo("en-GB", false)),
RemoteType = tbsite.RemoteType,
NoOfRemotes = (tbsite.NoOfRemotes == null) ? 0 : Convert.ToInt32(tbsite.NoOfRemotes),
GateType = tbsite.GateType,
NoOfRacks = (tbsite.NoOfRacks == null) ? 0 : Convert.ToInt32(tbsite.NoOfRacks),
};
我的模型:
public class Gate
{
public DateTime CalledInAt { get; set; }
public string RemoteType { get; set; }
public int NoOfRemotes { get; set; }
public string GateType { get; set; }
public int NoOfRacks { get; set; }
public string ClickToEdit { get; set; }
}
我收到以下错误。
“LINQ to Entities 无法识别方法 'System.DateTime Parse(System.String, System.IFormatProvider)' 方法,并且此方法无法转换为存储表达式。”} System.SystemException {System.NotSupportedException}
{"LINQ to Entities 无法识别方法 'Int32 ToInt32(System.Object)' 方法,并且此方法无法转换为存储表达式。"} System.SystemException {System.NotSupportedException}