数据库先创建实体框架6.1.1模型使用system.data.sqlite 1.0.93

2021-12-08 00:00:00 sqlite entity-framework

我有一个刚刚使用 nuget 更新的项目.此实体框架从 6.1 更新到 6.1.1,并将 sqlite 更新到 1.0.93.我想从我的最新数据库中更新我的模型.我做了以下步骤1) 来自数据库的模型2)选择sqlite数据库3) 生成

I have a project that I just updated using nuget. This updated entity framework from 6.1 to 6.1.1, and it updated sqlite to 1.0.93. I wanted to update my model from my latest database. I did the steps of 1) Model from Database 2) Select sqlite database 3) Generate

生成后,我收到如下错误消息.我安装了 1.0.93 设计时组件.有谁知道究竟是什么导致了这个错误.项目引用和版本都与上面显示的版本匹配.

After the generation I received the following error message shown below. I have the 1.0.93 design time components install. Does anyone know what exactly is causing this error. The project references and versions all match the versions shown above.

错误信息:

您的项目引用了最新的实体框架;然而和实体框架数据库提供者找不到与此版本兼容的数据连接.

Your project references the latest Entity Framework; however and Entity Framework database provider compatible with this version could not be found for you data connection.

更新:

我最终使用包管理器控制台手动安装了 6.1.0

I ended up installing 6.1.0 manually using the package manager console

Install-Package EntityFramework -Version 6.1.0

Install-Package EntityFramework -Version 6.1.0

然后在我的 csporj 文件中替换

Then in my csporj files replacing

包EntityFramework.6.1.1

packagesEntityFramework.6.1.1

包EntityFramework.6.1.0

packagesEntityFramework.6.1.0

我尝试从数据库创建 EF 设计器并从数据库创建代码优先,但我仍然遇到相同的错误.

I tried creating EF Designer from Database and Code First from Database but I am still getting the same error.

更新

我已按照 Tom 提供的说明进行操作,感谢您抽出宝贵时间进行深入回复,不胜感激.但是我无法让实体框架设计器使用 SQLite 1.0.93.我发现了什么:

I have followed the instructions Tom has provided, and thanks time for taking the time to respond in depth it is appreciated. But I cannot get the entity framework designer to work with SQLite 1.0.93. What I have found:

1) 当我按照 Tom 的描述从工具菜单添加 SQLite 数据源时,我看到了 SQLite 数据提供程序.

1) When I add the SQLite data source from the tools menu as Tom describes I see the SQLite data provider.

连接到数据源">

2) 但是当我重新启动 Visual Studio 时,数据源没有连接

2) But when I restart visual studio the data source is not connected

3) 数据源可以刷新,重启后有效

3) The data source can be refreshed and it is valid after restart

4) 添加新数据项但 SQLite 未列为提供者

4) Add new data item but SQLite is not listed as a provider

我仔细检查了注册表,EF6 附加到不变名称,SQLite dll 已在 GAC 中注册.我会尝试看看我还能找到什么,但此时我不确定要寻找什么.作为旁注,我尝试过 dotConnect,但它也不适用于 EF 6.1.1.

I have double checked the registry and EF6 is appended to the invariant name, the SQLite dlls are registered in the GAC. I will try to see what else I can find but at this point I am not sure what to look for. As a side note I have tried dotConnect and it does not work either with EF 6.1.1.

更新 2

有谁知道实体框架设计器是否有一个日志选项来找出可能发生的事情?

Does anyone know if the Entity Framework Designer has a logging option to find out what might be happening?

推荐答案

[ UPDATE :适用于 Visual Studio 2013 Update 4(专业版和旗舰版)和最新版本的 Sqlite 提供程序的更简单的解决方案和 EF,请查看下面发布的解决方案broslav".不知道它是否适用于 Express 版本...]

[ UPDATE : for an easier solution that works with Visual Studio 2013 Update 4 (Pro and Ultimate) and recent versions of Sqlite Providers and EF, look at the solution 'broslav' posted below. Don't know if it works with Express editions... ]

好的,这是一个建议.这不适用于 Visual Studio Express 版本.另外,我不确定如何让它为现有项目的更新工作.这是绝对的屁股痛.我还没有测试是否需要一切,但这应该有效:

Ok, this is a suggestion. This does NOT work for Visual Studio Express editions. Also, I'm not sure how to get it to work for an update of an existing project. And it is an absolute pain in the butt. I haven't tested if everything is required, but this should work:

首先,不要为 SQLite 使用 NuGet 包,而是从这里下载程序集安装程序:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

First, do NOT use the NuGet package for SQLite, but download the assembly installer from here: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

安装 32 位 Windows (.NET Framework 4.5.1) 安装程序:sqlite-netFx451-setup-bundle-x86-2013-1.0.93.0.exe (10.00 MiB)(不是 64 位版本).这是设计师唯一的一个.

Install the Setups for 32-bit Windows (.NET Framework 4.5.1) installer: sqlite-netFx451-setup-bundle-x86-2013-1.0.93.0.exe (10.00 MiB) (NOT the 64-bit version). This is the only one with the designer.

安装并选择安装在GAC中并安装Designer for VS13.

Install and select to install in the GAC and install the Designer for VS13.

对于以下内容,确切顺序很重要!

For the following, the exact order is important!

我制作了这些步骤的视频,请参阅:http://vimeo.com/103372740

在 VS13 中创建一个项目.明确地将构建定位到框架 4.5.1 和 x86.保存并构建.

Create a project in VS13. Target the build to framework 4.5.1 and x86 explicitly. Save and build.

接下来,从 NuGet 安装最新的 EF 6 包 (6.1.1).保存并构建.

Next, install the latest EF 6 package (6.1.1) from NuGet. Save and build.

手动添加对已安装SQLite程序集(包括设计器)的引用,在Assemblies下的Reference Manager下,您可以找到用于选择GAC中添加的四个程序集的Extensions选项:System.Data.SQLite Core + Designer + for EntityFramework + for LINQ.. 保存并构建.

Manually add references to the installed SQLite assemblies (including the Designer) , under the Reference Manager under Assemblies you can find the Extensions option for selecting the four added assemblies in the GAC : System.Data.SQLite Core + Designer + for Entity Framework + for LINQ.. Save and build.

然后通过工具"下的连接到数据库"创建与数据库的连接.在执行任何其他操作之前,先保存并构建,然后 重新启动 Visual Studio.在启动 ADO.NET 实体数据模型向导之前不要做任何其他事情,所以不要刷新数据库连接.

Then create a connection to your database via Connect to Database under Tools. Before you do anything else Save and Build and then RESTART Visual Studio. DO NOT DO ANYTHING ELSE before starting the ADO.NET Entity Data Model wizard, so DO NOT refresh the database connection.

添加 ADO.NET 实体数据模型,选择从数据库生成.您的数据库连接将显示在下拉列表中.保留它,但无论如何选择创建一个新连接并再次选择完全相同的数据库(就像您正在创建一个新连接).这听起来很傻,但很关键,见下图...

Add an ADO.NET Entity Data Model, select Generate from Database. Your database connection will show up in the drop-down list. Keep it there, but select to create a New Connection anyway and select the exact same database again (as if you are creating a new connection). It sounds silly, but it is crucial, see image below...

当我以这种方式实际添加 ADO.NET 实体数据模型时,它确实出现了令人讨厌的错误,但下一步"按钮是可选的,并且一切正常,无论如何(令人惊讶)!

When I actually Added an ADO.NET Entity Data Model this way it did present the annoying error, but the Next button is selectable and everything worked regardless (amazingly)!

设计师作品,检索数据和编写数据作品.

Designer works, retrieving data and writing data works.

尚未在另一台机器上测试部署...我使用的是 Win7 64 位.

Haven't tested deployment on another machine though... I'm using Win7 64-bit.

更改的更新:要获得正确的配置以实际访问数据库,您必须在执行所有操作后从 NuGet 安装 System.Data.SQLite.EF6 包以上,然后添加<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>到 App.Config 并删除其他提供程序并删除 <system.data></system.data> 之间的所有内容,否则您会得到一些异常.但请注意,这意味着每次要更新 EDMX 模型时,都必须将 App.Config invariantName="System.Data.SQLite" 更改为 invariantName="System.Data.SQLite.EF6",反之亦然.

CHANGED UPDATE: To get the correct configuration to actually access the database, you have to install the System.Data.SQLite.EF6 package from NuGet after doing all of the above, then add <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> to the App.Config and remove the other providers and remove everything in between <system.data></system.data>, otherwise you'll get some exception. But note that this means that every time you want to update the EDMX model, you have to change the App.Config invariantName="System.Data.SQLite" to invariantName="System.Data.SQLite.EF6" and vice versa.

** 这会变得荒谬吗?是的!这让我很头疼...... **

** Is this getting ridiculous? Yes, it is! And it gave me quite a headache... **

相关文章