. Net Universal Database Access Component SQL artisan Application Introduction 1

Source: Internet
Author: User
Description

SQL ArtisanIs based onC #Universal database access component; writeSQL ArtisanInstead of handling different database operations flexiblySQL ArtisanMore flexible and efficient database access writingCode. In addition to providingO/r mIn addition, it also provides a seriesSQLStatement-related objects. You can select the appropriate method to access the database under different circumstances. In addition to providing convenience and flexibility for object operations, Object-based condition objects maintain the traditionalSQLStatement condition compiling method, which makes it easier for the messenger to operate. The support for data functions is a major feature of components. The components support database functions in an extended manner. The call of functions allows you to create more complex query conditions to meet your actual needs.

NorthwindDatabase applications

The following are componentsQueryThe object is used for related queries (the Code also provides simpleO/r mRead operations), to facilitate direct useMSSQLOfNorthwindData. The following code mainly describes common order queries. The query involves three tables.: Orders, employees, customers;Two query conditions are involved in the query process: related customers and Related Employees.

Private VoidLoaddata ()

{

Using(Idatasession session = mappingcontainer. configcontainer. opensession ())

{

// Obtain an associated query object

IQUERY query = session. createquery (orders. TBL. Inner (customers. TBL, orders. _ customerid)

& Orders. TBL. Inner (employees. TBL, orders. _ employeeid ));

// Set the list of fields obtained by the query

Query. Selects =NewFieldadapter [] {orders. _ All,

Customers. _ companyName. ("CompanyName"),

(Employees. _ firstname + employees. _ lastname). ("Employeename")};

Expression exp =NewExpression ();

If(Drocustomers. selectedvalue! ="")// Add query conditions when you select a customer

{

Exp & = orders. _ customerid. At (orders. TBL) = drocustomers. selectedvalue;

}

If(Droemployees. selectedvalue! ="")// Add query conditions when an employee is selected

{

Exp & = orders. _ employeeid. At (orders. TBL) =Int. Parse (droemployees. selectedvalue );

}

Query. expreesion = exp;// Set query Conditions

Session. open ();

This. Ordersgrid. datasource = query. executedataset (). Tables [0];

This. Ordersgrid. databind ();

}

}

From the code above, it is very easy for the component to create an associated table.

Orders. TBL. Inner (customers. TBL, orders. _ customerid)

& Orders. TBL. Inner (employees. TBL, orders. _ employeeid)

Because it is an object-based operation, it can solve some minor errors in the writing process, such as incorrect table name writing or incorrect keyword writing.
The preparation of conditions is also extremely convenient.

If(Drocustomers. selectedvalue! ="")// Add query conditions when you select a customer

{

Exp & = orders. _ customerid. At (orders. TBL) = drocustomers. selectedvalue;

}

The above Code refersAnd.

 

Download application code

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.