other
End ADO.NET before analyzing, you have to mention the brothers between DataReader and DataSet
Argument.
On the author's information, almost all recommendations are recommended, and the rest is left.
I rarely, I'm decided by personal habits.
When studying ADO.NET, the author is also holding such an idea and remembers the information.
The terms summed up (just like the 23th of the year, it can be almost
After j), I think that I have a big exhibition in ADO.NET on ADO.NET.
It is a pity that the reality is not willing to make a few projects in a row, regardless of the size of the size.
Using a DataSet solution!
At this point, look back to see the most frequent PETSHOP project when learning ADO.NET.
Two comparisons, this is to see a little bit.
Simply put, PETSHOP adopts this "curved country" way to achieve data.
exchange:
DataReader Get Data => Create a Data Entity Class => According to Field Type Fill
According to physical classes => Add a data entity to the list class (only more than one data is returned)
occasion)
(Supplement: Adopt data entity or set class can be more convenient to implement Cache Manament,
And ordinary DataReader cannot meet this needs due to its data reading mode
This process is similar to that of DataAdapter.fill (), but only,
DataAdpater automatically creates DataReader to get data in Fill (), then create
DataTable (equivalent to data entity) and populates DataTable according to the field type, of course
If you might return multiple records, DataTable is completely handled, there is no need to implement columns.
The table is operated.
Maybe readers will have questions immediately: In this case, why does PETSHOP still need data
Physique?
There are still some differences.
First, the data entity class is a lightweight structure, which generally contains only the data field, no
What way of operation, this is better than DataTable or DataRow still has some performance advantages.
(It can be ignored when the amount of data is not large; on the other hand, the operation of the data entity is relatively
Simple, do not need developers to have any ADO.NET knowledge (actually DataTable
Said, this is nothing wrong), and some attributes can be.
However, according to the author's practice, these two does seem to be indiscriminate
DataReader program, the reasons are listed below:
(1) For occasions with large data volume, it is possible to use a batch reading method, which is a bit similar to the data paging effect of DataGrid;
(2) For simple data, the physical classes can also be copened that once the associated data is involved, it can only be written separately. And all of this, is very easy to handle in DataSet (for enterprise applications, most of the cases need to handle more complex data);
(3) DATATABLE "Natural" supports data collection operation, such characteristics are more easily controlled than "PETSHOP), which is more natural;
(4) The entity class needs to determine all data types when declaring. When data is filled, DataReader needs to pay another data type corresponding to the entity, and cannot have a slight error! In this regard, DataTable is very convenient and only one type is only a type of attention; (5) DataSet solutions can be very convenient to support serialization operations (such as remote, webservices), and the relationship with XML is more Intimate, this is also critical for interaction with other systems.
It has been analyzed some technologies and programs, and believes that readers have some experience. On the occasion of this receipt, if it is necessary to provide a "sum mention" here, the author's suggestion is very clear:
In enterprise application development, use Dataset (DataTable / DataView) Cache Management solution as much as possible!
In other developments, only the following 4 cases consider using DataReader (in terms of author experience, mostly using DataReader are the second case):
(1) When the resource requirements are more demanding, the resources here are mainly measuring memory and database connections;
(2) It is desirable to perform a custom processing when reading the database returns, for example, terminate the processing immediately after reading a record, or performs a calculation operation when reading.
(Tip: This situation is similar to the SAX (Simple API for XML) technology in XML, there is no need to read all XML data at once; the opposite, DOM (DOCUMENT OBJECT MODEL) requires that all XML data must be loaded Can you start the operation (MSXML4.0 has begun to allow only the XML document section to start operation, this is the later words)!)
(3) I only want to get the number of fields returned or returned to the record, such as:
String getNameByid (int NID) // Returns the name of the employee according to the employee ID, only need
// read the name field;
(Tip: This situation can generally be solved directly by performing a specific query or stored procedure)
(4) For some considerations (eg, the responsibility between each of the Layer in the N-Tier system), it is impossible (or prohibiting) to filter it through the database itself, then only use DataReader to read when reading Filter operation!
(Tip: Although DataView can also achieve this, its filtration premise is that all returned data must be read, so it is worse than DataReader!)
About the Author:
"Zhang Xuefeng, this article, is the senior development engineer of Bibo Global Development Center. He currently works in the Core / Eai department of China Shanghai Bibo Global Development Center, engaged in .NET technology research and related projects. You can pass xuefeng.zhang@bearingpoint .com Contact him. "