且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP NET CORE无法加载System.Data.SqlClient

更新时间:2022-10-17 22:14:14

本设计文档的目的是定义什么Entity Framework需要从SqlClient实现在EF7中使用,并支持ASP.NET vNext on C oreCLR。



有两个独立的组件需要这样做,System.Data.Common和System.Data.Common的SqlClient实现。本文件涵盖了这两个组件的要求。



https://github.com/aspnet/EntityFramework/wiki/Design-SqlClient-for-EF7


I have an aspnetcore solution that I split into three projects:

  • Project.Core dnxcore50 Main app - startup resides here and has Project.EF & Project.Model dependency
  • Project.EF dotnet5.4 class libary - dbcontext resides here and has Project.Model dependency. dotnet-ef tools reside here
  • Project.Models dotnet5.4 class library

Using the dotnet cli tooling (dotnet-ef) I was able to add migrations to the project successfully. However when I execute update database to apply the migrations, I get an exception that I cant seem to resolve.

C:\Users\chris\Documents\project\core\src\Project.EF
dotnet ef database update -s ..\Project.Core

Could not load file or assembly 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

If anyone has some direction on how I can get this final piece working, it would be greatly appreciated. Below is copy of my Project.EF project.json

{
  "dependencies": {
    "Microsoft.EntityFrameworkCore": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.Commands": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*",
    "Microsoft.AspNetCore.Hosting": "1.0.0-*",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-*",
    "OpenIddict.EF": "1.0.0-*",
    "Project.Models": "1.0.0-*"
  },

  "frameworks": {
    "dotnet5.4": {
      "imports": "portable-net451+win8",
      "dependencies": {
        "System.Data.SqlClient": "4.0.0-*"
      }
    }
  },

  "tools": {
    "dotnet-ef": "1.0.0-*"
  }
}

The purpose of this design document is to define what Entity Framework requires from a SqlClient implementation to be used in EF7 with support for ASP.NET vNext on CoreCLR.

There are two separate components required to make this happen, System.Data.Common and a SqlClient implementation of System.Data.Common. This document covers the requirements for both of these components.

https://github.com/aspnet/EntityFramework/wiki/Design-SqlClient-for-EF7