Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

asp.net mvc - Only parameterless constructors and initializers are supported in LINQ to Entities

There are several same questions that have same problem. But I cant find solution for me.

LinQ

var result = (from a in entity.TblAnalizorReadings
             group a by new { date = new DateTime(((DateTime)a.okuma_tarihi).Year, ((DateTime)a.okuma_tarihi).Month, ((DateTime)a.okuma_tarihi).Day, ((DateTime)a.okuma_tarihi).Hour, 0, 0) } into g
             select new AnalizorPivotChartModel
             {
                  okuma_tarihi = g.Key.date,
                  Gerilim_Faz1 = g.Max(x => x.Gerilim_Faz1),
                  Gerilim_Faz2 = g.Max(x => x.Gerilim_Faz2),
                  Gerilim_Faz3 = g.Max(x => x.Gerilim_Faz3)
              }).ToList();

Model

public class AnalizorPivotChartModel
{
    public Nullable<System.DateTime> okuma_tarihi { get; set; }
    public Nullable<decimal> Gerilim_Faz1 { get; set; }
    public Nullable<decimal> Gerilim_Faz2 { get; set; }
    public Nullable<decimal> Gerilim_Faz3 { get; set; }
}

I get error message as this question title. I can write more code if its neccesary.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
var result = entity.TblAnalizorReadings
    .GroupBy(a =>
        new {
            ((DateTime)a.okuma_tarihi).Year,
            ((DateTime)a.okuma_tarihi).Month,
            ((DateTime)a.okuma_tarihi).Day,
            ((DateTime)a.okuma_tarihi).Hour
        },
        (k, g) => new {
            okuma_tarihi = k,
            Gerilim_Faz1 = g.Max(x => x.Gerilim_Faz1),
            Gerilim_Faz2 = g.Max(x => x.Gerilim_Faz2),
            Gerilim_Faz3 = g.Max(x => x.Gerilim_Faz3)
        })
    .AsEnumerable()
    .Select(g => new AnalizorPivotChartModel
         {
              okuma_tarihi = new DateTime(okuma_tarihi.Year, okuma_tarihi.Month, okuma_tarihi.Day, okuma_tarihi.Hour, 0, 0),
              Gerilim_Faz1 = g.Gerilim_Faz1,
              Gerilim_Faz2 = g.Gerilim_Faz2,
              Gerilim_Faz3 = g.Gerilim_Faz3
          })
    .ToList();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...