如何在Visual Studio 2013中使用EF和SQLite

3
我想在Visual Studio 2013 Desktop Express中使用SQLite和Entity Framework。为此,我右键单击引用并安装了(包括所选依赖项)“System.Data.SQLite(X86 / x64)”(版本1.0.94.1)NuGet包。
现在,如果我向项目添加新元素并选择ADO.NET Entity Data Model,则看不到SQLite提供程序:我只有Microsoft SQL Server。
我的.NET Framework版本是4.5.1,操作系统是Windows 7。
这是我的App.config文件。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 </configSections>
 <startup>
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>
 <system.data>
   <!--
    NOTE: The extra "remove" element below is to prevent the design-time
          support components within EF6 from selecting the legacy ADO.NET
          provider for SQLite (i.e. the one without any EF6 support).  It
          appears to only consider the first ADO.NET provider in the list
          within the resulting "app.config" or "web.config" file.
-->
   <DbProviderFactories>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
      <remove invariant="System.Data.SQLite" />
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
   </DbProviderFactories>
 </system.data>
 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
       <parameters>
           <parameter value="mssqllocaldb" />
       </parameters>
    </defaultConnectionFactory>
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
 </entityFramework>
</configuration>

请查看我的博客文章:http://erikej.blogspot.dk/2014/11/using-sqlite-with-entity-framework-6.html - ErikEJ
3个回答

3

您必须从http://system.data.sqlite.org安装DDEX提供程序,但Express版本不允许安装任何扩展,如DDEX提供程序。

您可以安装新的Visual Studio 2013 Community。在那里,转到“工具”,“扩展和更新”,然后在搜索框中键入“sqlite ddex”,并安装它。


0

虽然您已经将SQLite的NuGet包添加到项目中,但这与用于脚手架数据模型的Visual Studio工具完全分开。

您可以从http://system.data.sqlite.org/安装Visual Studio的运行时支持-这应该允许您使用Visual Studio支持来创建您的模型。


0

我必须在Entity Framework的提供程序部分中添加这个:

<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

如果您按照EricEJ的教程操作,这个问题应该就能够解决了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接