gpt4 book ai didi

c# - C#aspnetCore否IEnumerable构造函数

转载 作者:行者123 更新时间:2023-11-29 18:18:49 25 4
gpt4 key购买 nike

我正在尝试将我的aspnet核心应用程序连接到linux服务器上的mysql db,我正在关注
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;
}

最佳答案

试试这个像这样修改人员类别

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

关于c# - C#aspnetCore否IEnumerable构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46767859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com