Step 1: Install the System. Data. Sqlite package in NuGet
Step 2: Generate object classes
I tried many times and tried to use Entity Framework Power Tools Beta 4 to connect Sqlite to generate Entity classes, but all failed. The final solution is to create a database with the same structure on SQL Server, after EF Power Tools connects to SQL Server to generate entity classes, remember to modify the database connection string in the configuration file:
<Add name = "testContext" connectionString = "Data Source = F: \ test. db; failifmissing = false" providerName = "System. Data. SQLite. EF6"/>
Note: EntityFramework 6 is used to connect to the Sqlite database provider instead of System. Data. SQLite. EF6, which is explained in the configuration file (App. config.
Step 3: The final content of App. config is as follows:
Reference content
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<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>
<ConnectionStrings>
<Add name = "testContext" connectionString = "Data Source = F: \ test. db; failifmissing = false"
ProviderName = "System. Data. SQLite. EF6"/>
</ConnectionStrings>
<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>
<Defaconnecticonnectionfactory type = "System. Data. Entity. Infrastructure. LocalDbConnectionFactory, EntityFramework">
<Parameters>
<Parameter value = "v11.0"/>
</Parameters>
</Defaultonfactory>
<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>
Step 4: Test the program
Using (testContext context = new testContext ())
{
List <Person> people = context. People. ToList ();
Foreach (Person item in people)
{
Console. WriteLine ("{0}, {1}", item. Name, item. Age );
}
}