C#aspnetCore没有IEnumerable构造函数

时间:2017-10-16 10:13:53

标签: c# mysql asp.net entity-framework razor

我试图将我的aspnet核心应用程序连接到linux服务器上的mysql数据库,我正在关注 This tutorial

当谈到启动应用程序时,它会从图像中给出这个错误。我不知道可能会出现什么问题,因为它从这个啧啧1:1开始。有线索吗?error 这是代码:

`https://pastebin.com/EryvVuCs` <- html


`https://pastebin.com/ieeHFz88` <- model


`https://pastebin.com/fMy3sNXE` <- model context

编辑:错误页面Error

public List<Person> GetAllPersons()
        {
            List<Person> list = new List<Person>();
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM person", new MySqlConnection("server=80.211.201.237;port=3306;database=test;user=root;password=DTZ$5zt:"));
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    //replace with your original columns names from the table
                    list.Add(new Person(reader.GetInt32("id"), reader.GetString("imie"), reader.GetDateTime("uro"), reader.GetString("pass")));
                }
            }
            return list;
        }

1 个答案:

答案 0 :(得分:0)

试试这个像这样的修改人类

public class Person
{
    private PersonContext context;

    [Key]
    public int Id { get; set; }

    public string Imie { get; set; }

    public DateTime Uro { get; set; }

    public string Pass { get; set; }

   public Person(int _Id,string _Imie,DateTime _Uro,string _Pass )
   {
      this.Id=_Id;
      this.Imie=_Imie;
      this.Uro=_Uro;
      this.Pass=_Pass;
   }
}

然后像这样修改你的GetAllPersons()函数

using (MySqlDataReader reader = cmd.ExecuteReader())
    {
      while (reader.Read())
      {
           //replace with your original columns names from the table
        list.Add(new Person(reader.GetInt32("id"),reader.GetString("Imie "),reader.GetDateTime("Uro "),reader.GetString("Pass"));
      }
    }