简体   繁体   中英

How to use EF with SQLite and Visual Studio 2013

I'd like to use SQLite with Entity Framework and Visual Studio 2013 Desktop Express.

To do that i have right click on Reference and installed (with selected dependecies) "System.Data.SQLite(X86/x64)" (version 1.0.94.1) NuGet packages

Now if i add a new element to my project and select ADO.NET Entity Data Model i don't see the SQLite Provider: i have only Microsoft SQL Server.

I have .NET Framework 4.5.1 and Windows 7.

This is my 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>

You must install the DDEX provider from http://system.data.sqlite.org - but the Express versions do not allow installation of any extensions like DDEX providers.

You can install the new Visual Studio 2013 Community. There, go to "Tools", "Extensions and Updates", the type "sqlite ddex" into the search box, and install it.

While you have added the nuget packages for SQLite to your project, this is completely separate to the Visual Studio tooling that would be used to scaffold a data model.

You can install the runtime support for Visual Studio from http://system.data.sqlite.org/ - this should allow you to use the Visual Studio support for creating your model.

I had to add this in the Providers section of Entity Framework:

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

If you follow EricEJ's tutorial, this should then work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM