Petapoco and SQLite.
For the lite version of the Orm,petapoco is really short, want to do a WPF demo, and then the Petapoco with SQLite integration, easy to use, is a good choice.
(1) = =Database configuration file<!--database Configuration-<appSettings> <!--sqlite--> <add key="SQLString"Value="~\app_data\olddemo.db"/> <add key="SQLString2"Value="| datadirectory| Olddemo.db"/> </appSettings>(2) Configuration ClassclassConfig { Public Static stringDatabasefile =""; Public Static stringDataSource {Get { return string. Format ("Data source={0}", configurationmanager.appsettings["SQLString2"]); } }} (3) = =Baseservices classusingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Data.SQLite;usingSystem.Linq;usingSystem.Runtime.Remoting.Messaging;usingSystem.Text;usingApp.Core.Constant;usingPetapoco;namespaceapp.core.service{ Public Abstract classBaseservice {PrivateIDbConnection Connection; PublicBaseservice () {connection=Newsqliteconnection (Config.datasource); } /// <summary> ///Querying all Objects/// </summary> /// <typeparam name= "T" >Generic Object</typeparam> /// <returns></returns> PublicList<t> query<t>() { varList =NewList<t>(); Try { stringClassName =typeof(T). ToString (); vardb =NewDatabase (connection); stringName =classname.substring (Classname.lastindexof ('.') +1, Classname.length-Classname.lastindexof ('.') -1); Connection. Open (); List= db. Fetch<t> (string. Format ("select * FROM {0}", name)); } Catch(Exception ex) {Throwex; } returnlist; } /// <summary> ///Delete Object/// </summary> /// <typeparam name= "T" >Generic Object</typeparam> /// <param name= "Objdata" ></param> /// <returns></returns> Public intDelete<t> (Objectobjdata) { varresult =0; Try { vardb =NewDatabase (connection); Connection. Open (); Result= db. Delete<t>(Objdata); } Catch(Exception ex) {Throwex; } returnresult; } /// <summary> ///Add a record/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "Objdata" ></param> /// <returns></returns> PublicT add<t> (Objectobjdata) {T result; Try { vardb =NewDatabase (connection); Connection. Open (); Result= (T) convert.changetype (db). Insert (Objdata),typeof(T)); } Catch(Exception ex) {Throwex; } returnresult; } }}
Petapoco and SQLite