The function of the data layer is to encapsulate the Data Types of some columns and the relationships between the definitions and tables.
1. Dataset Encapsulation
Advantage: DataSet used for crud can be generated by tools. In fact, the encapsulated information is nothing more than mainkey addtionalkey and other information.
Definition:
Each data table generally has a primarykey,
For a single table, primarykey = mainkey
For multiple tables, the primary table's primarykey = mainkey, from the table's primarykey = mainkey + addtionalkey
Principle:
Not to mention a normal single table, you only need to set the mainkey information.
Set the addtionalkey of the slave table.
Because the dataset information is not used, we store the information in datacolumn. extendproperity.
Disadvantages:
Datarow must be used for each operation, and the type verification cannot be achieved.
During batch update/deletion, an SQL statement must be executed for each update/Delete row, which is time-consuming.
2. updateobject/deleteobject
As the name suggests, this is an update/delete object. It is used to create data that can be updated/deleted in a table. It can also add fixed conditions and variable conditions.
We constructed an object that exists for batch update/deletion. When updateobject/deleteobject is submitted, only one SQL statement is generated.
3. Entity
Reason:
It is inconvenient to use datarow. You cannot perform type and data correctness verification as soon as possible.
Basedataset has a getentity setentity createentity method to generate a simple object based on the datatable.
Each object can be regarded as a row.
In this way, we can use orderentity entity = orderdataset. orderdatatable. createentity ();
Entity. orderid = "xxxxxx ";
.........................
Orderdataset. orderdatatable. setentity (entity );
It is more convenient than datarow.
In addition, after dataset obtains all the data for the entities in the primary table, the entities in the primary table also use a set of entities from the table.
For (INT I = 0; I <orderentity. orderitementities. Count; I ++)
{
Orderitementity itementity = orderentity. orderitementities [I];
// Do something
}