With the help of the extended functions, this version can make database operations easier and more convenient. In terms of database operations, we will provide you with a new experience. The main improvements include the following:
- Conditional expressions can be combined with strings to create complex query conditions more flexibly.
- The load _ method can be used to obtain the relevant ID data object based on the value object.
- The Series-1 query method can be expanded to perform data operations directly on the string SQL, including querying and retrieving the query object data. Other objects are not required during the operation.
- Extensions can perform operations directly on Stored Procedure objects.
The above series of extensions allow you to operate data directly without referencing related condition objects or database context objects, making data operations simpler and more flexible.
Object acquisition and saving
VaR EMP = 3. Load _ <employee> (); EMP. Notes + = "_ test"; EMP. Save _();
The above is a simple way to get the object based on the ID value, modify and save. Because the extension method is easy to cause conflicts with other methods, so the _ is added to the method to distinguish.
SQL Execution
In the original version, some SQL statements must be processed and some objects must be used. you must create an SQL Execution object to process the SQL statement. however, in version 1.7, you no longer need to do this. You can directly perform the operation on the basis of a string of an SQL statement.
"Delete * from employees". Execute ();
The above is a simple SQL statement for executing a delete statement. Of course, you can also execute a query and return a list of objects.
Foreach (VAR item in "select * from employees". List <employee> () {console. writeline (item. firstname );}
Parameters need to be set for query
Foreach (VAR order in "select * from orders where employeeid = @ p1 ". parameter ("p1", 3 ). list <order> () {console. writeline ("orderid: {0} \ t orderdate: {1}", order. orderid, order. orderdate );}
Stored Procedure execution
Custorderhist COH = new custorderhist (); COH. customerid = "alfki"; COH. execproc _();
You only need to create a stored procedure description object, and set the relevant parameter values to directly execute the processing. Of course, you can also execute and return a query result.
Custorderhist COH = new custorderhist (); COH. customerid = "alfki"; foreach (VAR data in COH. execproctoobjects _ <custorderhistdata> () {console. writeline ("{0} \ t {1}", Data. productname, Data. total );}
Condition integration of object conditions and string descriptions
Processing complex SQL queries in the original conditional expressions becomes more troublesome. In actual situations, some complex conditions are not directly intuitive, therefore, the new conditional expressions can be directly integrated with the conditions described in string and generate new expression objects for data operations.
Expression exp = new expression (); exp & = order. orderdate> = "1996-7-1"; exp & = "employeeid in (select employeeid from employees where region = @ P1 )". add ("p1", "wa"); foreach (VAR order in Exp. list <order> () {console. writeline ("orderid: {0} \ t orderdate: {1}", order. orderid, order. orderdate );}
Summary
the simplification of the above operations makes it easier and more flexible to operate databases.
component Official Website: http://www.ikende.com/SmarkData.aspx
Source Code site: http://smark.codeplex.com/