Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

后端 未结 13 2273
[愿得一人]
[愿得一人] 2020-12-08 04:18

I recently upgraded/updated Entity Framework in an old project from version 4 or 5 to version 6. Now I get this exception:

An exception of type \'Syst

13条回答
  •  醉梦人生
    2020-12-08 05:04

    Hendry's answer is 100% correct. I had the same problem with my application, where there is repository project dealing with database with use of methods encapsulating EF db context operation. Other projects use this repository, and I don't want to reference EF in those projects. Somehow I don't feel it's proper, I need EF only in repository project. Anyway, copying EntityFramework.SqlServer.dll to other project output directory solves the problem. To avoid problems, when you forget to copy this dll, you can change repository build directory. Go to repository project's properties, select Build tab, and in output section you can set output directory to other project's build directory. Sure, it's just workaround. Maybe the hack, mentioned in some placec, is better:

    var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
    

    Still, for development purposes it is enough. Later, when preparing install or publish, you can add this file to package.

    I'm quite new to EF. Is there any better method to solve this issue? I don't like "hack" - it makes me feel that there is something that is "not secure".

提交回复
热议问题