My database access framework 1

Source: Internet
Author: User

 

 

1. Background

The company's project initially used the Entity Framework, but its performance was unsatisfactory for the company's needs, so it developed a database framework suitable for the company's needs. Although there are many similar
Framework. Although each has its own strengths, it is very short. I am quite touched by cyq. data's ideas. The release of cyq made me feel confused. The style of mysoft seems to be linq, which triggers my use of expansion.
Thank you.

2. Introduction

Qin. data is a general database processing framework (including mssql access sqlite excel mysql DB2 ORACLE... as long as you are willing to implement the interface ). it is easy to perform common database operations (add, delete, modify, and query ). its performance is almost pure ADO. NET. emit is used for entity query. If you are not satisfied, the Code Generator of this framework can directly generate pure ADO. net SQL format. its main features are performance and convenient operations.

 Related advanced functions:

Multiple databases are supported at the same time: You can use multiple databases in one project at the same time.

Convenient transaction support: you only need to set a single attribute to achieve transaction operations.

Powerful UI system: original interface components that support common and complex configurations. (the most efficient and convenient and beautiful page-free components, powerful and beautiful table controls, and convenient HTML editor ....)

Convenient and easy-to-use syntax sugar query function: Makes your query more convenient

Convenient Database Upgrade: You don't have to worry about the troubles caused by the database. It provides you with the data layer generation function and directly compiles the data.

Powerful Code Generator: Provides code and entity generation at the entire data layer, pure ADO support and code compilation functions, and supports multiple types of databases.

3. initialize Configuration

Configuration File<Deleetask>
<Add key = "web" value = "NO"/> // whether it is web Development
<Add key = "databaseName" value = "MSSQL"/> // Database Type
<Add key = "linkString" value = "Server = www.wwe.com.cn; database = HD01SystemDB; Uid = ss; Pwd = ss" <
/Span> // connection string
</AppSettings>

 


Query

Query entities

DBTool db = new DBTool (Table. EventBaseSet); // specify the Table or // DBTool db = new DBTool (Table. TableName_Qin );

Db. Where = EventBaseSet. EventID _. Equals _ (3); // lock the record
Var data = db. GetEntity <EventBaseSet> (); // retrieves an object

 
Query specified fields
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. Equals _ (32 );
Var name = db. GetOneField <string> (EventBaseSet. EventID _);

 
Multi-field Query
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. Equals _ (32 );
Var row = db. GetDestinationFields (EventBaseSet. EnabledBodyHtml _, EventBaseSet. Days _);

Compound condition Query

DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. BiggerThan _ (32). And _
(EventBaseSet. EventName _. Contains _ ("hello"). OR _ (EventBaseSet. Days _. BiggerThan _ (22 ));

Nested Query

DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. Creater_CreaterID _. Equals _ (CreaterSet. CreaterID _. SelectFrom _ (Table. CreaterSet). Where _(
CreaterSet. Name _. Repeated SSTR _ ("")));
Custom object query (including multi-Table query)
Var SQL = "Copied SQL statement ";
Var data = DBTool. Database. GetEntity &
Amp; lt; custom entity> (SQL );

Add dataDBTool db = new DBTool (Table. CitySet );

// Db. StartTransaction = true; // whether to enable the transaction

Db. SetInsertField (CitySet. CID _, "10001 ");
Db. SaveChanges ();
Var newID = db. NewID; // newly generated auto-incrementing primary key



 


Data Update operations

Db. SetUpdateField (CitySet. CName _, "City 1 ");
Db. SetUpdateField (CitySet. CID _, "1--1 ");
Db. Where =
CitySet.
CID _. Equals _ (2)
Db. SaveChanges ();


Data deletion

Db. DeleteWhen = EventBaseSet. EventID _. Equals _ (2 );
Db. SaveChanges ();

 

Paging FunctionFront-end code:

<% = Tool. GetPager ("", "display paging location", "1000 pieces of data", "10 pieces of data per page") %>

Call the Page code of the background.

Public List <HallPromotion> GetHallPromotionList (int startIndex, int endIndex, string orderby)
{
DBTool db = new DBTool (Table. PromotionSet );
Db. Where = "1 = 1 ";
Var count = db. GetCount ();
Var list = db. GetPageListDesc <PromotionSet> (startIndex, endIndex, orderby); // specify the index page.
Var haList = new List <PromotionSet> ();
//..........
Return ret;
}

 

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.