Data transfer type between BLL and Dal

Source: Internet
Author: User
Tags scalar

Today, we will discuss how data is transmitted between the BLL layer (business logic layer) and the Dal layer (data access layer.
If you have written a three-tier architecture before, you must be familiar with the following data transmission methods for BLL and Dal layers:

Datareaders
Dataset
Dataset
Custom object class
Scalar Value

The first is datareaders. Datareader is a fast object that loads data at a time. Through some of his methods and attributes, you can easily obtain his data. However, he also has many disadvantages. One is that he must be able to read data only when connected to the database, in this way, it is possible that we forget to close the database after reading the data, so that other users cannot connect to the database. Therefore, you must explicitly close the database connection. The second disadvantage is that it is read-only, that is, we cannot directly read data from datareaders and then update the data to the database, if you want to update the data, you must select another method to update the data. The third disadvantage is that it is not a strong type, that is, it cannot detect the data type, which may cause type Matching errors during data transmission, our compilers often find it difficult to detect these non-strong errors in these places.

The second is dataset. Dataset is a projection of database tables in memory. It is completely unconnected to the data source. As long as the data has been added to the dataset, there is no connection to the data source. Because it is connectionless, you don't have to worry.ProgramWill close the data connection. Dataset also supports adding, changing, and deleting data. You can also use dataset to represent complex data and associated data. At the same time, dataset and datareader are not strongly typed. Therefore, when using dataset, you must determine whether the type of each field matches correctly. Besides, dataset is more overhead than datareader because it returns more information about the underlying data table.

The third is the typed dataset. Typed Dataset refers to the use of dataset as the underlying data structure and then adding a strong type to dataset, making it easier for callers to access data and read data.Code. This means that you can use smart sensor development tools to develop your projects. A strong type also means that it provides compile-time detection instead of runtime detection. Although the typed dataset is very cool, I do not plan to use a strongly Typed Dataset. If you continue to read it, you will find that more cool types represent data tables. Of course, typed dataset also has a disadvantage, that is, when the underlying data table changes, we must rewrite the dataset we created.

The fourth is the custom object class. The custom object class is a class created by the user based on the database. Generally, we create attributes to represent each field, use List or arraylist to record a table. If we use a custom object class to transmit data, we generally use datareader to read records in the database and assign values to the custom object class, then, pass the custom object class to The bll layer (business logic layer. In this way, we can manage data connections in the Dal layer. This is a good thing. Similarly, we can use a structure instead of a class to represent data. Because the structure is of the value type, the overhead of the structure is less than that of the class. The custom entity class makes the program easier to read and supports intelligent inductive development because it is strongly typed.

The disadvantage of custom object classes is that we must manually create them. When we create a project, we will find that this part of the work of creating object classes become boring, because it is mechanical action. At this time, we may use tools to create entity classes, but this will often increase the complexity of the project. In addition, when the underlying table changes, the custom object class must also change. The custom object class deals with datareader, so its type detection will be postponed until runtime, which forces us to determine that our object class matches the data table without any difference.

The last one I want to introduce is the scalar value. When we want to add, update, or delete data, we can pass a separate field to the Dal layer. The performance of using a scalar value is higher than that of other types because it is a simple value type. However, the scalar value is not so convenient to use, and it is especially embarrassing to represent tables in the database.

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.