[英]Entity Framework DateTime using view
I have the following view in my DB 我的数据库中有以下视图
create view myview
as
select
date_reception ,
location ,
parameter
from mytable
in the model i have the following class 在模型中,我有以下课程
public partial class full
{
public Nullable<System.DateTime> date_reception { get; set; }
public string location { get; set; }
public string parameter { get; set; }
}
And i execute the following query in controller 我在控制器中执行以下查询
DateTime dt = new DateTime(2015,01,01);
var temp = (from p in db.full
where (p.date_reception > dt)
group p by p.parameter into g
orderby g.Count() descending
select new StringIntType
{
str = g.Key,
nbr = g.Count()
}).ToList();
After running the query keeps executing till i get this error message : 运行查询后,将继续执行直到收到此错误消息:
System.Data.Entity.Core.EntityCommandExecutionException System.Data.Entity.Core.EntityCommandExecutionException
public partial class full
{
public DateTime? date_reception { get; set; } //it's nullable
public string location { get; set; }
public string parameter { get; set; }
}
it seems that problem is your datetime object. 看来问题出在您的datetime对象上。
DateTime dt = new DateTime();
DateTime dt2 = new DateTime();
if (DateTime.TryParse("2015, 01, 01", out dt2))
{
dt = dt2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.