2016-07-22 108 views
1

我试图在.NET Core 1.0项目中使用ADO.NET而不使用实体框架来连接数据库。ASP.NET Core项目中缺少SqlDataAdapter

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using ASP_NETCore3.Models; 
using System.Data; 
using System.Data.SqlClient; 
//using System.Configuration; 

namespace ASP_NETCore3.Repository 
{ 
    public class LineasRepository 
    { 
     private SqlConnection con; 

     private void connection() 
     { 
      //TODO: Implementar variables de confuracion obtiendolas desde appsettings.json 
      string constr = "Data Source=mylocaldb\\sql08;Initial Catalog=empresas;User id=user;Password=secret;Integrated Security=SSPI;"; 
      con = new SqlConnection(constr); 
     } 

     public List<LineasModel> GetAllLineas() 
     { 
      connection(); 
      List<LineasModel> LineasList = new List<LineasModel>(); 
      SqlCommand com = new SqlCommand("select * from CATLIN", con); 
      com.CommandType = CommandType.Text; 
      SqlDataAdapter da = new SqlDataAdapter(com); 
      DataTable dt = new DataTable(); 
      con.Open(); 
      da.Fill(dt); 
      con.Close(); 

      LineasList = (from DataRow dr in dt.Rows 

         select new LineasModel() 
         { 
          cod_lin = Convert.ToInt32(dr["COD_LIN"]), 
          nom_lin = Convert.ToString(dr["NOM_LIM"]), 
          margen = Convert.ToString(dr["MARGEN"]), 
         }).ToList(); 


      return EmpList; 
     } 
    } 
} 

正如你看到的,我可以使用System.Data.SqlClient的,但由于某种原因编译器说,SqlDataAdapter的缺失。

我该怎么办?它可以修复从NuGet安装另一个软件包?

+0

您将需要在project.json中添加对所需程序集的引用 –

+0

显然,我将不得不使用另一种方法,我会尝试使用Micro-ORM Dapper。 –

+1

@Mr_LinDowsMac考虑使用NReco.Data库(https://github.com/nreco/data),它还提供无模式数据访问的API。作为奖励,您可以使用与数据库无关的抽象查询,而不是在代码中堆砌SQL。 –

回答

1

看来.NET的核心没有为SqlDataAdapter提供实现,甚至DataTable

这是this page

关于

的DataTable和DataSet和SqlDataAdapter的也都没有发现报价...? ?对于.NET Core 1.0版本的数据访问技术>仅限于低级别的ADO.NET接口(IDbConnection,IDbCommand等)或富EF内核。 >然而,您可以使用第三方库来替代DataRow/DataTable/DataAdapter,例如NReco.Data

0

我重新编译MySQL.Data对.NET 2.0的核心与MySQL的DataAdapter和CommandBuilder的编译。我已经测试至今的作品。

https://github.com/amjtech/MySQL.Data

享受。

+0

请不要添加“谢谢”作为答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你就可以[提出问题和答案](https://stackoverflow.com/help/privileges/vote- )你发现有帮助。 - [来自评论](/ review/low-quality-posts/18049804) –

+0

这不会提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/18049804) –

+0

虽然此链接可能会回答问题,但最好在此处包含答案的重要部分并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/18049804) – Saranjith