EF6 Code first perfectly supports SQLite

Source: Internet
Author: User
Tags sqlite sqlite database

To EF6 Code First mode support SQLite has a few steps:

One, need to install Sqlite-netfx451-setup-bundle-x86-2013-1.0.92.0.exe to let vs add ado with SQLite optional

1) go to Http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki to download the corresponding. NET version of the installation file (* Note the download file name with bundle, This will do plug-in support for VS )

2) Installation

To select all installations

Tick the two check boxes below to support vs

Then the next step ...

This interface will stay for a long time, but do not care about it, not to manually close it, this is registered vs plug-in

When you see this, you can turn on vs for SQLite add

3) Vs Add entity model

You'll see this, and then you can have fun with SQLite.

Second, EF6 support

Once the first step is complete, the program can use EF's code frist, but at the same time, there is a problem, that is, the program is running on other computers can not find System.Data.Sqlite program support, unless the first step to repeat.

The System.Data.Sqlite package in Nuget solves this problem.

1) Installing the NuGet package

Find SQLite online in the NuGet admin interface, add the first one, and add three more.

You can also enter commands in the NuGet console: Install-package System.Data.Sqlite

2) Modify Config

The red line is to be added manually, the code is as follows

<entityFramework>
<defaultconnectionfactory type= "System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantname= "System.Data.SqlClient" type= "System.Data.Entity.SqlServer.SqlProviderServices, Entityframework.sqlserver "/>
     <provider invariantname= "System.Data.SQLite" type= "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 "/>
<provider invariantname= "System.Data.SQLite.EF6" type= "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 "/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
     <remove invariant= "System.Data.SQLite"/>
<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.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>

PS: When adding Sqlite to a solid model, only the 5.0 framework is optional, which means that EF5 is added first, so uninstall EF5 before adding the System.Data.Sqlite package

At this point, you can use the EF6 to manipulate the SQLite database at vs.

EF6 Code first perfectly supports SQLite

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.