- Download the source file compression package from Https://github.com/qingask/PetaPoco.NetCore
- Unzip the file PetaPoco.Multiple.cs, PetaPoco.NetCore.cs
- Place the System.Data.SQLite.dll file into the bin file, which needs to be obtained from SQLite official corresponding to the frame set level corresponding bit file, which should be available directly through NuGet.
- Method 1:
- Add DbProviderFactories class and inject SQLite instance into Petapoco
Public Static classdbproviderfactories{Internal Static ReadOnlydictionary<string, dbproviderfactory> configs =Newdictionary<string, dbproviderfactory>(); Staticdbproviderfactories () {registerfactory ("Microsoft.Data.Sqlite", sqlitefactory.instance); } Public StaticDbProviderFactory GetFactory (stringproviderinvariantname) { if(Configs.containskey (providerinvariantname)) {returnConfigs[providerinvariantname]; } return NULL; } Public Static voidRegisterfactory (stringProviderinvariantname, DbProviderFactory Factory) { if(Configs.containskey (providerinvariantname)) {Configs[providerinvariantname]=Factory; } Else{configs.add (providerinvariantname, Factory); } } Public Staticienumerable<string>Getfactoryprovidernames () {returnConfigs.Keys.ToArray (); }}
- Configure Web. config
<name= "Petapococonn" connectionString= "Data source=| datadirectory| Demo.db "/>
- Link syntax
var db=New Database (new sqliteconnection (configurationmanager.connectionstrings[) petapococonn"]. ConnectionString));
- Method 2:
- Configure Web. config
<System.Data> <dbproviderfactories> <Removeinvariant= "System.Data.SQLite"/> <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>
- link string:
< connectionstrings Span style= "COLOR: #0000ff" >> < add /span>name = "Petapococonn" connectionString =" Data source=| datadirectory| Demo.db " providerName =" System.Data.SQLite " /> </ Span style= "COLOR: #800000" >connectionstrings >
- Auxiliary classes:
Public Static class dbscoure { publicstatic Database sqlitedatabase () { var conn = configurationmanager.connectionstrings["petapococonn"]; return New Database (Conn. ConnectionString, Conn. ProviderName); } } Call mode:var db=dbscoure.sqlitedatabase ();
Organize two Petapoco connect SQLite database method