如何在ASP .NET Core Web App中使用Entity Framework ADO.NET?

问题描述

我正在使用Visual Studio 2017中使用ASP .NET Core的Web应用程序,并实现React和Redux。我选择了Visual Studio的React和Redux模板来启动项目。我想使用实体框架的ADO.NET工具创建模型。我已经在WPF桌面应用程序项目中做到了这一点,但从未在Web应用程序中做到过。当我转到Add -> New Item -> Data时,它没有像wpf项目中那样显示ADO.NET选项。是否可以使用此工具来创建模型,还是可以使用网络应用程序? 目前,我正在执行类似的Read和Add方法

[HttpGet("[action]")]
public List < Client > FetchData() {
  List < Client > clients = new List < Client > ();
  var connection = GetConnection();

  var command = new MysqLCommand("SELECT * FROM client;",connection);
  using(MysqLDataReader reader = command.ExecuteReader()) {
    while (reader.Read()) {
      clients.Add(new Client {
        Id = int.Parse(reader.GetValue(0).ToString()),Name = reader.GetValue(1).ToString(),LastName = reader.GetValue(2).ToString()
      });
    }
  }
  return clients;
}

[HttpPost("[action]")]
public Client AddClient() {
  Client client = new Client {
    Name = "Jon",LastName = "Doe"
  };
  MysqLConnection conn = GetConnection();
  using(var command = conn.CreateCommand()) {
    command.CommandText = "INSERT INTO client(NAME,LAST_NAME) VALUES(@name,@lastname)";
    command.Parameters.AddWithValue("@name",client.Name);
    command.Parameters.AddWithValue("@lastname",client.LastName);
    command.ExecuteNonQuery();
    client.Id = (int) command.LastInsertedId;
    conn.Close();
  }
  return client;
}

但是我认为对于很多事情,我可以使用Enitity Framework模型通过linq轻松地完成。 如何创建像ADO.NET这样的模型?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)