In traditional development models, there is usually an entity layer (here the entity and the entity in the MVC development framework are not a concept ),
The classes in this entity layer are the ing of database tables in applications, and even the class names correspond to the tables one by one. Although they are classes, they only contain attributes,
No way.
This type of object is used to transmit data. It is concise and clear. For example, when a method has more than three parameters, and these three parameters represent
When corresponding fields are used, they can be replaced by an object class.
The above is an advantage of the entity class, of course, its advantage is not only that.
How many formats are there when the data layer returns the query data?
Generally, a single field, a single able, or even DataSet is returned.
A single field is very clear. We will not mention it for the moment. Since it is a able, it is a set of rows, and each row can use the entity class.
So when the data returns the dataTable, it can be directly converted to an object set. In this case, when the outer layer is called
More intuitive, you can directly know which specific object to operate on.
This method is generally used in the following scenarios:
For a single table query, when a table connection query is obtained, there is an inheritance relationship between the tables. The results of a join Table query without an inheritance relationship cannot be represented by an entity, so it cannot be mapped to an entity set.
One principle in the development process is encapsulation change.
SQL statements must be used to operate data tables at the data layer. Select * from TableName
Select ColumName from TableName, which is in the business or other factors. Generally, our database field will be modified. At this time, we must find and replace this field in the entire project.
Since the entity layer is the link between database and application ing, why not expand the entity layer?
We add a field in the object class, whose value is the name of the field in the data table. In each project and method, the corresponding field needs to be called through a specific object class,
When the database changes, the entity class is regenerated, and other projects do not need to change. The SQL statements at the data access layer are neat and clear.
Author dreamhappy