【问题标题】:How to solve may not be abstract and must be include a default constructor?如何解决可能不是抽象的,必须包含默认构造函数?
【发布时间】:2021-02-16 13:06:02
【问题描述】:

我有一个数据库 [![as this picture][1]][1]

我想从这个数据库中获取一个图表,当我尝试在控制器端使用 SQL 查询时,我得到了这样的错误; [![这是错误类型][2]][2]
这是我的控制器代码;

 public ActionResult Index2(String makineadi, DateTime? startdate, DateTime? enddate)
        {
            var data = entities.Database.SqlQuery<DataPoint>("SELECT Sıcaklık, Recete_Sure From Recete Where Machine_IP ='" + makineadi + "' and Tarih between'"+startdate+"' and '"+enddate+"'").ToList();
            ViewBag.DataPoints = JsonConvert.SerializeObject(data);
            return View();
        }

这是我将图表转换为 JSON 序列化的类定义;

 [DataContract]
        public class DataPoint
        {
            public DataPoint(int Sıcaklık, int Recete_Sure)
            {
                this.Sıcaklık = Sıcaklık;
                this.Recete_Sure = Recete_Sure;
            }

            //Explicitly setting the name to be used while serializing to JSON.
            [DataMember(Name = "Sıcaklık")]
            public Nullable<int> Sıcaklık { get; set; }

        //Explicitly setting the name to be used while serializing to JSON.
        [DataMember(Name = "Recete_Sure")]
            public Nullable<int> Recete_Sure { get; set; }
        }

我应该怎么做才能修复它? [1]:https://i.stack.imgur.com/ObwWR.png [2]:https://i.stack.imgur.com/zQNgO.png

【问题讨论】:

    标签: sql asp.net-mvc charts canvasjs


    【解决方案1】:

    在类中添加默认构造函数。

    [DataContract]
    public class DataPoint
    {
        public DataPoint()
        {
        }
        public DataPoint(int Sıcaklık, int Recete_Sure)
        {
            this.Sıcaklık = Sıcaklık;
            this.Recete_Sure = Recete_Sure;
        }
    
        //Explicitly setting the name to be used while serializing to JSON.
        [DataMember(Name = "Sıcaklık")]
        public Nullable<int> Sıcaklık { get; set; }
    
        //Explicitly setting the name to be used while serializing to JSON.
        [DataMember(Name = "Recete_Sure")]
        public Nullable<int> Recete_Sure { get; set; }
    }
    

    解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 2022-08-15
      • 2013-09-09
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多