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