Organize two Petapoco connect SQLite database method

Source: Internet
Author: User
Tags sqlite sqlite database connectionstrings

  1. Download the source file compression package from Https://github.com/qingask/PetaPoco.NetCore
  2. Unzip the file PetaPoco.Multiple.cs, PetaPoco.NetCore.cs
  3. 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.
  4. Method 1:
    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 (); }}

    2. Configure Web. config
      <name= "Petapococonn"  connectionString= "Data source=| datadirectory| Demo.db "/>

    3. Link syntax
      var db=New Database (new sqliteconnection (configurationmanager.connectionstrings[)  petapococonn"]. ConnectionString));

  5. Method 2:
    1. 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>

    2. 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  >  

       

    3. 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

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.