Efficient and easy-to-use data access framework function Preview (2) (Tutorial)

Source: Internet
Author: User

1. High Performance (this framework uses a pure ADO. NET Framework to avoid performance loss caused by Linq and reflection );

2. ease of use (simple configuration, SMART awareness, and assistance from code generators, and SQL (self-performance optimization ));

3. multi-database support (the entire framework is designed in factory mode. Currently, it supports oracle, mssql, mysql, sqlite, and acess. If necessary, it can be expanded by itself)

4. New query functions (write code like linq)

 

Let's introduce the simple configuration file.

 

<Deleetask>
<Add key = "web" value = "No"/> <! -- Whether it is website development -->
<Add key = "databaseName" value = "MSSQL"/> <! -- The database type can also be MYSQL, SQLITE, ACCESS... -->
<Add key = "linkString" value = "Server = mainserver; database = HD01SystemDB; Uid = sa; Pwd = 123"/>
</AppSettings>

 

Let's take a look at our code generator.

 

// Function Code Preview

Public static void Main (string [] args)
{
// 1 single-value query -----------------------------------
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. Equals _ (2 );
Var str = db. GetOneField <string> (EventBaseSet. Domain _);
Console. WriteLine ("Single-value query:" + str );

// 2 single row query ---------------
Db. Where = EventBaseSet. Creater_CreaterID _. Equals _ (3 );
Var entitye = db. GetEntity <EventBaseSet> ();

Var row = db. GetDestinationFields (EventBaseSet. Domain _, EventBaseSet. HeadBGColor _);
Var domain = row [0];

// 3 multi-row query ------------------------------
Db. Where = EventBaseSet. Creater_CreaterID _. BiggerThan _ (3 );
Var list = db. GetEntitesList <EventBaseSet> ();
Var table = db. GetDataTable ();

// 4 composite query --------------------
Db. Where = EventBaseSet. EventName _. Contains _ ("er ").
And _ (EventBaseSet. Domain _. inclusstr _ ("ertertert "));
Var domainName = db. GetOneField <string> (EventBaseSet. Domain _);
Console. WriteLine ("Composite query:" + domainName );
// 5 Multi-Table query --------------
Db. Where = "cross-query statement ";
Db. GetEntitesList <custom type> ();



// 6 add data
Db. SetInsertField (EventBaseSet. Creater_CreaterID _, 33 );
Db. SetInsertField (EventBaseSet. EnabledBodyHtml _, true );
Db. SetInsertField (EventBaseSet. EventName _, "test ");
Db. SaveChanges ();
Var id = db. NewID;

// 7 update data ------------------------
Db. Where = EventBaseSet. EventID _. Equals (3 );
Db. SetUpdateField (EventBaseSet. EnabledBodyHtml _, false );
Db. SetUpdateField (EventBaseSet. Domain _, "www.badi.com ");
Db. SaveChanges ();

// Query the first N rows ----------------
Console. WriteLine ("First N rows query :");
Db. Where = EventBaseSet. EventID _. BiggerThan _ (0 );
Var list = db. GetTopList <EventBaseSet> (4 );
Foreach (var element in list ){
Console. WriteLine (element. EventName );
}
// 9 Delete data -------------------
Db. Where = EventBaseSet. Creater_CreaterID _. Equals (3 );
Db. DeleteWhere (db. Where );
Db. SaveChanges ();

// Pure SQL support
Var deleteSql = "delete from EventBaseSet where EventID = 2 ";
DBTool. Database. ExecuteOneSql (deleteSql );

// 10 json supported
Var json = "";
DBTool. UpdateDatabaseByJSON (json );
DBTool. InsertDatabaseByJSON (json );

// 11 support for pure ADO. NET queries (Code Generator) and provide Code Generator

// 12 Stored Procedure Support
SuperSqlParameter p = new SuperSqlParameter ("@ a", DbType. Int64, 3 );
SuperSqlParameter p2 = new SuperSqlParameter ("@ B", DbType. DateTime, DateTime. Now );
Var list = new Queue <QinParameter> ();
List. Add (p );
List. Add (p2 );
DBTool. Database. ExecuteProc ("myproc", list );

Console. WriteLine ("Press any key to continue ...");
Console. Read ();
}

 

If you are interested, I will release it for free. It is currently being used in the development of our company (the performance of the Entity Framework is very low and you are afraid to use it)

First, provide the library dll and generator. If you are interested, please pay attention to (Files/humble/Debug.zip)

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.