Analysis. Net Data Access Layer technology (d)
This is a large number in a few years ago, let. NET guy excitedtechnology. On the author, at that time, as long as I brought the subject is generallyin the j2ee guy inand returnhimselfENB (relative EJB) or NCMP (relative CMP) what.
Finally, we can. NET framework 1.2 (or VS.NET 2004Whidbey can be found in Yukon, the current version is Beta) in view of its "" in J.
First of all, let us take a look at the code used to write ObjectSpaces is what (the employee is still using the above example):
/ / Initialize ObjectSpace
SqlConnection conn = new SqlConnection ( "Data Source = localhost;
Integrated Security = SSPI; database = Northwind ");
ObjectSpace os = new ObjectSpace ( "map.xml", conn);
/ / EmployeeID return in accordance with its Title
Employee oEmp = (Employee) os.GetObject (
new ObjectQuery (typeof (Employee), "ID = 1"));
/ / Note: The actual field is called: EmployeeID
string strTitle = oEmp.Title;
/ / In accordance with City to return to all eligible Employee
ObjectSet oSet = os.GetObjectSet (
new ObjectQuery (typeof (Employee), "City = '" Seattle'"));
/ / NOTE: instead of returning DataTable, but the target set
foreach (Employee oEmp in oSet)
... ... / / Note: You can do any operation on oEmp
Code for the second paragraph above, there is a solution, that is, to ObjectReader alternative ObjectSet, which contains the differences, similar to ADO.NET 1.0 (included in ADO.NET also known as ObjectSpacesd the ADO.NET 2.0) in the DataSet / DataTable and DataReader different between (have to admire the consistency of Microsoft in the show before and after the wily J).
Careful analysis of the code above, it can be found in front of it and OJB discussed the similarities are striking (OJB Author only painting in the basic class diagram, but enough of such thinking can be seen close to)!
For example: ObjectSpace category OJB basically provides QueryFacade function of; ObjectQuery category OJB basically provides the Criteria function; At the same time, the two solutions and the use of the same configuration file to store the O / R Mapping information; and applications the general will through the two types of data operations, very convenient. Some slight differences may be the return to form in the data (this, ObjectSpaces more careful consideration, you can reference the code above), but this has been the source of the actual realization of the impact.
If the call ObjectSpaces code given in the previous period under the ADO.NET code to write to make a comparison, it is not difficult to see, ObjectSpaces given more to read and understand the code, even if not familiar with the overall framework for the development of ADO.NET staff, but also makes it easy to start (the only RDBMS code involved only when the need to establish a database connection). For those who have been familiar with the ADO.NET or have come into contact with O / R Mapping (such as: J2EE under Hibernate) friends, they really can be described as a piece of cake!
From. NET Framework 1.2 documentation can be aware of, ObjectSpaces provided a total of three namespaces, the overall structure is clear:
ObjectSpaces, Query in the code above, had the experience can be guessed from the name, which is mainly responsible for the provision of basic access interface from outside (such as inquiries, increase / delete / change, etc.) and resolve a variety of query (such as object filtering ), Schema namespace is used to operate the main O / R Mapping configuration file, and rename the other two types of space services.
In ObjectSpaces in, O / R Mapping the main configuration file refers to map.xml, is the name of the document can be replaced, to compare like with like OJB in repository.xml. The other two describe the structure of the database structure and objects of the configuration file is also very important: RSD.xml (Relational Schema Definition), OSD.xml (Object Schema Definition). They can be interpreted as a Typed DataSet's XSD documents, without which all the data / object Mapping and Validation will be "unlawful" J!
In this paper, the author is not prepared to a depth of ObjectSpaces exploration Sample will not provide any of its superiority in this respect,. NET Framework SDK already has provided a rich package.
Author only hope that, if the point of view from the DAL to analyze, ObjectSpaces technology can bring to us what it means farewell from DataReader / DataSet, or for developers to bring new troubles?
The benefits of not more than that can be understood to mention a few:
(1) ObjectSpaces All access to data objects, greatly ease a lot of developers of SQL (or RDBMS) phobia;
(2) of the database structure is relatively simple change, only you need to modify configuration files without re-compile code (compared to OPF will be mapping. NET Attribute code the way to the package, it is more flexible and convenient);
(3) for more complex database structure changes, as the only targets of the operation, it also revised a number of simple than before;
(4) the use of the O / R Mapping configuration file, database design and development can be carried out DAL, mutual influence of the lowest level;
Is less than we need to be concerned about the topic:
(1) the current version does not support the Chinese (never the subject of J) inquiries, a bad mood!
(2) the current version only supports the above version of SQL Server 2000 database system, the weak (this is a very interesting limitations, interested readers may wish to think about what are the reasons in the end)!
(1,2 a quote from. NET Framework SDK Document, on these two points have been excluded from a lot of eager friends. And the author of participation. NET project, although not one, but as a result of frequent use of Oracle, will have to temporarily afford to spare the pain J)
(3) performance issues. ObjectSpaces Although DataReader provides a similar function (ObjectReader), but after all, need to fill a strongly typed data, in any case there will be losses, if returned to the quantitative data, and will have to be considered a problem;
(4) or performance problems. Dongdong map.xml is good, but how to optimize it for the right to visit and Validation (based on RSD.xml, OSD.xml), after all, takes time, and even in some cases (more complex database structure), this will lead to more than point 3 of the more serious consequences;
Something less than that in fact there is no need to worry too much, after all, there is no perfect solution, how to choose will depend on your own decision.
Finally in this chapter, the author gives a summary of their own, 12 for your reference. At all after the analysis, the authors have tried to combine their practice of providing "My program (written in)" I hope you readers can help.
.Net Database Articles
- Set the primary key for the DataTable
- DBNull to use skills
- Access the database through ADO.NET
- Standardized database skills (MS)
- Use DataAdapter and DataSet to update database [C #]
- vb.net access database picture Montaque (original)
- vb.net access database picture Montaque (original)
- . NET connection using oledb and csv format sybase connection
- . net multi-lingual and data set to deal with multiple data tables (2)
- Binding Dataview examples (beginners can see, it is simple, but very useful)
- ASP.NET: Dispaly data from an Excel Spreadsheet
- Operation of a database of examples of category (b. Provider category)
- ADO programmers designed for ADO.NET
- Paging Database Results in ASP.NET (Prt2) (reprint: http://www.4guysfromrolla.com/) [board-level: primary]
- Microsoft Access using ADO.NET data unlock (2)
- Detailed study of ADO.NET (e) - DataReader
- DataGrid common solution: a state in the page to delete records
- The use of the ADO.NET Data Service to protect the integrity of (3)
- A man and three woman's story [ ". Net framework for program design," notes study multi-chapter event _ XI sample]
- Analysis. Net Data Access Layer technology (d)
Can't Find What You're Looking For?
Rating: Not yet rated