使用视图的实体框架日期时间



>我的数据库中有以下视图

create view myview
as 
select  
      date_reception ,
      location ,
      parameter
      from mytable

在模型中,我有以下类

 public partial class full
 {
    public Nullable<System.DateTime> date_reception { get; set; }
    public string location { get; set; }
    public string parameter { get; set; }
 }

我在控制器中执行以下查询

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();

运行查询后继续执行,直到我收到此错误消息:

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; }
 }

似乎问题出在您的日期时间对象上。

DateTime dt = new DateTime();
DateTime dt2 = new DateTime();
if (DateTime.TryParse("2015, 01, 01", out dt2))
{
   dt = dt2;
}

最新更新