EF is very powerful, unfortunately for SQLite does not support Codefirst mode (need to design the database table structure in advance), but the data operation of SQLite is very useful.
Use Sqlitemanager to create a database and a table:
Install EF6 through NuGet and System.Data.SQLite
(will automatically pack the other three)
Add Configuration content:
Database connection
1 <connectionStrings>2 <add name="studentcontext" connectionstring="Data source=studentdb.sqlite" providername=" System.Data.SQLite.EF6"/>3 </connectionStrings>
Configuration file:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Configuration>3 <configsections>4 <!--for more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -5 < Sectionname= "EntityFramework"type= "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=6.0.0.0, culture= Neutral, publickeytoken=b77a5c561934e089 "requirepermission= "false" />6 </configsections>7 <connectionStrings>8 <Addname= "Studentcontext"connectionString= "Data source=studentdb.sqlite"ProviderName= "System.Data.SQLite.EF6"/>9 </connectionStrings>Ten <Startup> One <supportedruntimeversion= "v4.0"SKU=". netframework,version=v4.5 " /> A </Startup> - <EntityFramework> - <defaultconnectionfactorytype= "System.Data.Entity.Infrastructure.SqlConnectionFactory, entityframework" /> the <providers> - <providerInvariantName= "System.Data.SqlClient"type= "System.Data.Entity.SqlServer.SqlProviderServices, entityframework.sqlserver" /> - <providerInvariantName= "System.Data.SQLite.EF6"type= "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> - <providerInvariantName= "System.Data.SQLite"type= "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> + </providers> - </EntityFramework> + <System.Data> A <dbproviderfactories> at <Removeinvariant= "System.Data.SQLite.EF6" /> - <Addname= "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" /> - <Addname= "SQLite Data Provider"invariant= "System.Data.SQLite"Description= ". Net Framework Data Provider for SQLite"type= "System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/> - </dbproviderfactories> - </System.Data> - </Configuration>
Test it:
EntityFramework Connect SQLite