在通过nuget下载EF6并尝试运行我的项目后,它返回以下错误:
没有为ADO找到实体框架提供程序。NET提供程序,使用不变名称'System.Data.SqlClient'。确保提供者在应用程序配置文件的“entityFramework”部分中注册。更多信息请参见http://go.microsoft.com/fwlink/?LinkId=260882。
在通过nuget下载EF6并尝试运行我的项目后,它返回以下错误:
没有为ADO找到实体框架提供程序。NET提供程序,使用不变名称'System.Data.SqlClient'。确保提供者在应用程序配置文件的“entityFramework”部分中注册。更多信息请参见http://go.microsoft.com/fwlink/?LinkId=260882。
当前回答
我有同样的问题,只是复制了应用程序配置文件从包含DBContext的项目到我的测试项目
其他回答
YourModel扩张。然后打开YourModel.Context.tt下的YourModel.Context.cs类。
我在使用部分添加了以下一行,错误为我修复了。
使用 SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices;
您可能必须在每次自动生成文件时将这一行添加到文件中。
当你通过Nuget安装实体框架6时。EntityFramework。SqlServer有时会错过另一个可执行文件。只需将Nuget包添加到该项目。
有时以上对测试项目不起作用
要在测试项目中解决这个问题,只需将这个方法放在测试项目中:
public void FixEfProviderServicesProblem()
{
var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
这个方法从未被调用过,但根据我的观察,编译器将删除所有“不必要的”程序集,而不使用EntityFramework。SqlServer stuff测试失败。
引用实体框架所在项目的启动项目需要在bin文件夹中包含以下两个程序集:
EntityFramework.dll EntityFramework.SqlServer.dll
在启动项目的.config文件的<configSections>中添加<section>将使第一个程序集在该bin目录中可用。你可以从实体框架项目的.config文件中复制:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
要使第二个.dll在bin文件夹中可用,尽管不实际,但可以从实体框架项目的bin文件夹中手动复制。 一个更好的选择是在实体框架项目的Post-Build Events中添加以下几行,这将使该过程自动化:
cd $(ProjectDir)
xcopy /y bin\Debug\EntityFramework.SqlServer.dll ..\{PATH_TO_THE_PROJECT_THAT_NEEDS_THE_DLL}\bin\Debug\
我有一个控制台应用程序和类库。在类库中,我创建了实体数据模型(右键单击类库>添加>新项目>数据> ADO。NET实体数据模型6.0),并在控制台应用程序中放置引用。因此,你有控制台应用程序,它引用类库,在类库中,你有EF模型。当我试图从表中获取一些记录时,我遇到了同样的错误。
我通过以下步骤解决了这个问题:
Right click to solution and choose option 'Manage NuGet Packages for Solution' and NuGet package manager window will show up. Go to 'Manage' option under 'Installed packages' TIP: Entity Framework is added to Class Library, so you will have EntityFramework under 'Installed packages' and you'll see 'Manage'option Click on 'Manage' option and check to install package to project which has reference to class library which holds EF model (in my case I set check box to install package to console app which had reference to class library which had EF model inside)
这就是我所要做的一切,一切都很完美。
我希望这对你有所帮助。
In my case, everything was working properly then suddenly stopped worked because I think Resharper altered some changes which caused the problem. My project was divided into the data layer, service and presentation layer. I had Entity framework installed and referenced in my data layer but still the error didn't go away. Uninstalling and reinstalling didn't work either. Finally, I solved it by making the data layer the Startup project, making migration, updating the database and changing the Startup project back to my presentation layer.