Analysis of the data access layer technology under the .NET Posted by Admin On April 27, 2004 (middle) Since .NET truly enters the developer, "efficiency" two words have always become the topic of many programmers . Whether it is from the development model (Cross Language), the system framework (.NET Framework), it is not a victorious person who has a variety of easy tools (VS.NET). l
Since .NET truly enters the development person, "efficiency" two words have always become the topic of many programmers. Whether it is from the development model (Cross Language), the system framework (.NET Framework), it is not a victorious person who has a variety of easy tools (VS.NET).
At the same time, on the other hand, whether .NET can truly compete for the heavy responsibility of enterprise application (Enterprise Application), but still arguing, it is very different.
Generally speaking, there are many aspects, such as security, performance, scalability, ease of use. In this article, the author is more willing to discuss the relevant technologies of the data access layer under the .NET, which may be a wide focus on the sensitive topic of the N-Tier Architecture, and for most For developers, this may also be the most depressed part of the project, or even the most controversial part.
In the following discussion, in order to unify, the author temporarily refers to the data access layer is referred to as DAL (Data Access Layer).
l Analysis problem
After simple statistical analysis, it is not difficult to find that DAL is afraid, not for the problem of technical itself, even in contrast, many developers believe that this is one of the most technical parts (on the author's experience) In view, the development time of this layer is generally short, and many developers are unwilling to bear "hardships"), but the architecture needs or certain thoughts (such as: Dal and DAL) have only joined this so-called first Four layers (traditional three-layer architecture did not propose DAL ideas).
DAL's proposal, it is indeed a huge challenge to the traditional architectural model. The purpose of joining is also hoping to borrow him further increase productivity. In this mode, ideal is: Most developers get rid of DBA suffering, or thoroughly Direct relationship with the database, SQL pain will go away from us, the entire OO world is quiet.
However, ideal is ideally, it is necessary to pass the project inspection.
Next, the author attempts to analyze a relatively popular and representative solution to see if there are some valuable conclusions, and provide some reference for us to design and implement DAL in the future.
u ado.net
First, mention the DAL under .NET, immediately reflecting the eye blind is ADO.NET.
That's right, almost all DAL solutions (please allow the author to use Solution rather than
Framework must be developed from it, no choice, this is also .NET features
Implementation (Comparison J2EE).
Exclude business factors and CLR itself, ADO.NET truly brought things to us.
Not much, it is worth mentioning, DataSet (for the author experienced, using more DataTable and DataView). From Microsoft's early memory database (Memory Database)
Some people ask for today's DataSet, this is a tribute to the words.
Can deal, in short, there is a bit of certain, it is the choice of DataSet, .NET
Dal can be like today, and everyone's ideas can be more open.
Duwamish
There are a lot of good SAMPLE this aspect, the most classic universal development package for Microsoft's strong recommendation: duwamish.
For friends who want to learn .NET DAL design, this is a good starting point, this
Common profile, you can refer to "9CBS Development Master, 2003.11", this article is not
Take it again.
The author used the Duwamish program in one project of its own participation, which is limited to work
The period, I feel that this is a good reference, I didn't do in-depth analysis. Recall now
Get up, there is still a lot of shortcomings.
For a simple example, Cache Management is not considered in the DUWAMISH scheme.
And this is an enterprise application, some of the questions that have to be considered;
Aspect, although DUWAMISH say goodbye to the SQL statement (all the stored procedures are implemented),
But database traces are still very obvious, such as: definition of certain field names, association table name
Definition, etc.
There is also a very headache problem that is reflected in the development process. First, then
Some simple data sheets are relatively easy to implement, and some data sheets containing each other
When our Dal engineers felt pressure, they later, almost done DBA.
Work earlier in the modeling of the database, only, this time the database script is changed.
C # implementation (or said: replacing the database structure with an OO characteristic DataSet)
Yes.
It may, DUWAMISH's implementation is more classic, but in practical applications, sometimes
It tastes BEST PractICE. Take our project, although successful delivery, no matter from the mold
The type of multiplexed angle, or the development efficiency, it is very successful. Set of popular words:
In fact, we can do better!
PETSHOP
Another DAL implementation worth a reference on ADO.NET is a famous PetShop.
Of course, similar to duwamish, the famous arrogance is not necessarily practical. Although PetShop is
Make up the shortcomings of duwamish in some respects, for example: support multiple numbers through Factory
According to the reservoir, the Cache mechanism is introduced, providing more convenient SQL Helper, but also
Other questions have been brought. Among them, the most troublesome is the introduction of SQL statements, but also
It is a different SQL statement for different data deposits (mainly SQL Server and Oracle)
The parameter representation is different.
On the other hand, PETSHOP does not use DataSet to be more concise
Entity object (Model), but it still converts the result of DataReader to the included entity pair
The list of pictures of the icon is deployed in line. From this sense, it can be said that the soup is not changed. even,
In some occasions, for example, data is required, or navigate between the master-slave data, but more inconvenient (at this time, simple Collection or List is unable to meet demand, DBA
With DAL developers can only provide other methods to achieve purposes).
From the above two examples, we can see that even in Microsoft's development team,
There is no consistency on the issue of DAL. More details on this area, interested
Friends can refer to the following article:
Http://www.microsoft.com/china/community/column/67.mspx.
Actual combat
The two solutions are analyzed, let us see their respective advantages and insufficient, and the complex environment of enterprise-class applications is unlikely to ask a framework that can solve all problems, so they can only According to the specific situation, the specific analysis is specifically analyzed.
The author has participated in the development of a (.NET) large outsourcing project, fortunately, his DAL is designed, deeply shocked, here to discuss together with friends.
Take the Northwind database with SQL Server as an example, as follows, a para-based call code (the author has adjusted on some names):
/ / Return to its Title according to EMPLOYEEID
Boemp = new Employeedal ();
Boemp.keys ["EMP_ID"] = 1; // Note: The actual field name is: EMPLOYEEID
Boemp.select ();
String startle = Boemp ["EMP_TITLE"]; // Note: The actual field name is: Title
......
/ / Return to all qualified EMPLOYEEs according to City
Boemp = new Employeedal ();
Boemp.keys ["EMP_CITY"] = "seattle";
Boemp.select (); // Note: This method is identical to the above call
Datarable DTEMP = Boemp.Table;
If you don't consider the object creation (can use Object Pooling or Cached Object), the actual code is only two lines!
More surprisingly, the above Employeedal class does not have any true realization code, just declare the class name, then inherited from a general base class! !
The most elegant place is not here. In fact, even in that base class, you can't see the gang dispute between SqlConnection or Oracleadapter.
I believe everyone also guess, it's right, it is borrowed from the implementation of PETSHOP, using the Factory mode to ensure that DAL can apply to different data sets. However, this implementation is still very different from PETSHOP: At least, it does not produce different SQL statements, and there is no different parameter call mode (SQL Server usually uses "@" symbols, Oracle general use ":": " Symbols), all gangstere the colleagues!
Among them, it is of course benefiting from the implementation skills of Factory, but more important factors are still exempt from design. In fact, in the .NET Framework, this design of the cornerstone is provided, which is white, which is the interface in System.Data (such as IDBConnection, iDataAdapter, etc.). Based on such a design, we will no longer need to provide different data access to different data deposits for each DAL class. For example: In PETSHOP, the order data needs to implement the Order class, which is natural, the system implements the Order class for SQL Server and Oracle, respectively, and operates with the methods provided by Different Provider (SqlClient, OracleClient). When actual calls, PetShop dynamically create a real ORDER class through the Factory mode and activate the corresponding method, a scheme for different data deposits.
In fact, PETSHOP has been more flexible. If you can save the "writing of different Order classes", you really send to the Buddha to get J. And all of these features, in this project participated in the project, it has been fully available!
As for "Employeedal (of course, including all of all DAL classes), there is no real implementation code. VIEW) Store in the XML file according to NameSpace.
You may have seen it, in theory, even only one DAL class can complete all the above work! However, in practice, different DAL classes may still have some subtle differences on data processing (such as data check, format conversion, etc.).
In general, in such a large project, it is impossible to ask all developers (except DBA, Dal Framework Developer to learn about the all aspect of ADO.NET, although the author has research, but in this project, Only two classes from the end of the end: DataTable, DataView (even if transaction does not need to know)! 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 when returning more than one data)
(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 of payment is only necessary;
(5) DataSet solutions can be very convenient to support serialization operations (such as remote, webservices), while relationships with XML are more intimate, which 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 development, only the DataReader is considered in the following four situations (for the author's experience, mostly using the DataReader are the second case): (1) The resource is more demanding, the resources here refer to 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!)
u o / r mapping
O / R Mapping's full name is: Object Relational mapping, main purpose is to build a mapping relationship between traditional RDBMS and Oo Language, so that developers completely detach the data for a long-lasting sea.
About O / R mapping or recently comparing O / X mapping (You can refer to "programmer, 2004.01, p86"), may require a special article to discuss, this paper is mainly for the advantages and disadvantages of existing programs. Simple profiles and provide reference information in some practices.
Comparison of J2EE platforms, O / R mapping under .NET can be described as there is no history, and has not yet been tested programs. However, with the attention of major manufacturers, the pace of .Net O / R mapping has begun to keep up with the steps of this item to join the J2EE, and will not make more Many developers put .NET camp? J), which also makes numerous fatigates who come back and forth in SQL CLAUSE or ADO.NET to see "Light Road".
Next, let's take a look at the Solution of this slogan to discuss more than ADO.net.
? Open Source
Open source has always been with .NET keeps a certain distance, O / R mapping is even more than, but in terms of the author's download trial and source analysis, individuals think that the following two solutions still have a certain reference value: OPF, OJB.
Introduction to these two open source projects, you can refer to "Programmer, 2004.01, P13". The full name of OPF is: Object Persistent Framework.
The full name of OJB is: Object Relational Bridge.
In implementation, the idea of these two programs is completely different, with respective representation.
The route of the OPF is a bit similar to Typed DataSet or Borland Eco (please refer to the following description), the implementation is relatively simple, providing more source level control; and the OJB implementation is similar to Microsoft Objectspaces (please refer to the following introduction), use The way the configuration file is complicated, relatively complicated.
The basic framework of these two programs is as follows:
OPF:
It is not difficult to see from the figure:
(1) The Persistent class plays a DataSet role. In addition to the regular object data operations, the PersisTent operation can also set the relationship between different objects (such as the primary relationship, collection relationship, etc.) in the code generated by the Borland ECO. Slightly one or two), this is also the reason why the above say "provide more source level control";
(2) PersistentSqldataManager played the role of DataAdapter, performs real database operations by pre-set Commands; in actually written Employee Data Manager, developers do need to provide basic SQL statements, just like setting in SQLCommond (Borland ECO is further, replacing SQL with OCL);
(3) ObjectBroker's role is very important, it is the bridge between the objects and the data, the RegisterPersistent method establishes this virtual (Object) and reality (RDBMS) relationship;
(4) In the declaration of the Employee Business Object, the correspondence between the object attribute and the database field is reflected in the .NET Attribute mechanism, so modify it is still more convenient, although it is not flexible than the configuration file (please refer to OJB) Introduction), such as: need to recompile, developers have to pay attention to database fields.
OJB:
It is not difficult to see from the figure:
(1) The implementation of the scheme is more complicated, but the user needs to be actually written (only written EMPLOYEE Business Object), the key is to introduce the configuration file; at the same time, we are There is no need to call the RegisterObject method in similar OPF solutions (please refer to the OPF class diagram above), all of which (even database connection information), the system is as good!
(2) In this scenario, the SQL command is thoroughly replaced by the Criteria class, while QueryFacade acts as an Adapter functionality, communicating with the database through the true Command of PersistenceBroker;
(3) Whether it is a repository.xml configuration file, or the Criteria, QueryFacade class, we can find similar implementations in ObjectSpaces (please refer to the following introduction), at the same time, the author believes that this way It is also more in line with the spirit of O / R mapping, reducing the burden of developers! (4) OJB has a very cool tool "repositorygen.exe", can be used to generate the repository.xml configuration file (the same, source code is unpaid J), this, even ObjectSpaces can not do (want Think so many fields, attributes, associations, mapping, simply let people go crazy J)!
Microsoft ObjectSpaces
This is a technique that makes many .NET Guy outstrettime a few years ago. As far as the author said, at that time, as long as I mentioned this topic, I usually returned to J2EE Guy's ridicule, I can't help myself, I'm also eNB (relative EJB) or NCMP (relative CMP).
Finally, we can find it in the "Fang Rong" in the .NET Framework 1.2 (can be found in VS.NET 2004WHIDBEY or YUKON.
First, let's see what the code written by ObjectSpaces looks like (still using the Employee example above):
// Initialize ObjectSpace
SqlConnection conn = new sqlconnection ("Data Source = localhost;
Integrated Security = SSPI; Database = Northwind ");
Objectspace OS = New ObjectSpace ("Map.xml", Conn;
/ / Return to its Title according to EMPLOYEEID
Employee OEMP = (Employee) Os.GetObject
New ObjectQuery (TypeOf (Employee), "ID = 1"));
// Note: The actual field name is: EMPLOYEEID
String startle = OEMP.TITLE;
......
/ / Return to all qualified EMPLOYEEs according to City
ObjectSet oset = Os.GetObjectSet
New ObjectQuery (TypeOf (Employee), "City = '" seattle' ");
// Note: Returns not DataTable, but an object collection
Foreach (Employee Oemp In OSET)
{
... // Note: You can do anything about OEMP here.
}
In response to the second paragraph of the above, there is a solution that replaces ObjectReader instead of ObjectSet, which is similar to the DataSet in ADO.NET 1.0 (ADO.NET containing ObjectspacesD, also known as ADO.NET 2.0). / DataTable is different from DataReader (have to admire Microsoft's exhibited foreigners in front and rear and rear and conformance). Carefully analyze the above code, you can find that it is an amazing similar point with the OJB discussed earlier (OJB Care only draws the basic graph, but it can see this ideological approach)!
For example, the ObjectSpace class provides QueryFacade feature in OJB; the ObjectQuery class provides the criteria feature in OJB; at the same time, the two solutions do not penetrate the same configuration file to store O / R mapping information; It is also very convenient to perform data operation through these 2 classes. A slight difference may be on the data return format (this, ObjectSpaces considerate more details, you can refer to the code above), but this has not imposed on the actual code.
If you make a comparison of the code written under ObjectSpaces in ADO.NET, it is not difficult to see that the code given by ObjectSpaces is more readily read and understood, even if it is not familiar with the development of ADO.NET overall architecture. Personnel, you can easily pick up (only if the code involving RDBMS is only required to establish a database connection). For friends who have been familiar with ADO.NET or have been touched O / R mapping (such as hibernate under J2EE), it can be taken as a small dish!
From the .NET Framework 1.2 document, you can know that ObjectSpaces provides a total of 3 namespaces, and the overall structure is very clear:
System.Data.Objectspaces
System.Data.ObjectSpaces.Query
System.Data.Objectspaces.Schema
Objectspaces, Query has been seen in the code above, can guess from the name, they are responsible for providing basic access interfaces (such as query, increase / deletion / change, etc.) and analyzes various query conditions (such as object filtering, etc. ), SCHEMA namespace is primarily used to operate the O / R mapping profile and serve the class in other two namespaces.
In ObjectSpaces, the O / R mapping profile mainly refers to Map.xml. The name of this file can be replaced at will, which is similar to the repository.xml in OJB. The other two configuration files describing the database structure and object structure are also very important: RSD.XML (Relational Schema Definition), OSD.XML (Object Schema Definition). You can understand the XSD files in Typed DataSet, without them, all data / object mapping and validation will be "illegal" J!
In this article, the author is not prepared to explore ObjectSpaces, nor will it provide any Sample to explain its superiority. In this regard, .NET Framework SDK has long provided rich package.
The author just hope that if it is analyzed from DAL, ObjectSpaces technology can bring us what it means to bid farewell to DataReader / DataSet, or bring new troubles to developers? If you don't have much benefits, you can justify only a few cases:
(1) Objectspaces all use object-like access data, greatly eased the SQL (or RDBMS) phobia of many developers;
(2) For the relatively simple database structure, you only need to modify the configuration file, there is no need to recompile the code (compared to the mapping relationship in the OPF, it is more flexible and convenient);
(3) For more complex database structure changes, the modified work is more simple than before because of the object operation.
(4) After using the O / R mapping profile, database design and DAL development can be performed separately, and the impact of mutual effects has also dropped;
Insufficient is what we are more concerned about:
(1) The current version does not support Chinese (eternal topic J) query, not cool!
(2) The current version only supports the database system, weak (this is a very intriguing restriction, interested readers may wish to think about what is the reason)!
(1, 2), these two points have excluded a lot of friends who are eager to try. And the author's participation .NET project is not affected by 1, but since Oracle often uses Oracle, you have to take love. J)
(3) Performance issues. Although ObjectSpaces also provides a DataRectReader, but after all, it is necessary to make a data power type fill, no matter how losses will be lost, if the amount of data returns to the data, it will be a question that must be considered;
(4) Or performance issues. Map.xml is a good stuff, but how to optimize its access and correct validation (RSD.xml, osd.xml) take time, even at some time (database structure is more complicated), this will result Three more serious consequences;
Saying some shortcomings, in fact, there is no need to worry too much. After all, there is no perfect solution, how to pay attention to your own decision.
In this chapter, the author gives a summary for you to refer to one. After all the analysis, the author also tried to provide "My Program (Writing)" in conjunction with your own practice, I hope to help readers. Borland Eco
Borland, which provides "How fast provincial" components, known as the "ENTERPRISE CORE Object", which does not say its technical features before Microsoft: ECO (Enterprise Core Object), with its technical characteristics, with modeling tools TOGETHER seamless integration, has to admire Borland's efforts under the unified development process.
According to the definition of Borland in Eco, ECO is: Model Drive (MDA-Driven) Development Framework (Framework). (Views: According to the author's view, the core issue of database applications is DAL, which is the topic of this article needs to be discussed)
Obviously, from MDA-Driven, Database Application and FRMEWORK these very shocking words are not difficult to see, it is the very powerful core competitiveness before Borland (of course, including IDE, Components, Cross Platform) In terms of aspects, a company can have so many excellent products, which is really respectful)!
Previously, developing database applications on the Borland platform is very convenient, component visual design can basically take a relatively simple application module. Nowadays, the last layer has finally launched their own O / R mapping solution!
With the author's point of view, under TOGETHER excellent Modeling tools, combined with the number of two strengths in Framework development (only by artistic, VCL Framework can take the Oscar Award in this field), the current ECO is absolutely steadily. Net O / R mapping first chair!
(Note: Objectspaces has not been released, not considered.)
Introduction to the specific development of ECO, you can refer to "Programmer, 2003.12, P99", "Programmer 2004.01, P97", "Programmer, 2004.02, P100".
Hereinafter, the author mainly analyzes the benefits of using ECO development and its insufficient, for reference.
advantage:
(1) Compared with the Typed Dataset (Type Dataset, it can be automatically generated in vs.net) has obvious advantages than the UML /
Except for free switching between code, ECO can support custom data types
And the type of calculation (friends who have experienced Delphi know this is an exception
Powerful weapon);
(2) IDE provides powerful design support, various tools, components, which is also the most good field of Borland;
(3) Integrate TOGETHER modeling tools, playing MDA to the 3rd place, please refer to the shortcomings analysis below;
(4) Introduced Object Constraints Language (OCL), the standard gets the official support of the OMG organization. Name: OO SQL (object-oriented SQL), a great gospel for unfamiliar SQL developers;
Disadvantages:
(1) The resource consumption is large, and the ordinary machine is difficult to experience its advantages; this, Rational XDE is done quite good;
(2) There must be a learning curve, such as: OCL (Object Constraints Language), although it is different from SQL, but it is still very simple from the syntax angle; as the author's own experience, it may learn XQuery (query language in XML) or Opath (Query language used in ObjectSpaces) should be more relaxed; (3) pure commercial products, only Architect version contain this feature, and ObjectSpaces is directly included in .NET Framework, it is independent of VS.NET version, which can pass .NET Framework SDK is directly used;
(4) Light excess MDA: DAL developers can generate a database script in ECO, whether DBA also needs to design in ECO?
For enterprise applications, the author consists of: MDA development model is more applicable to development of various layers of DAL above, such as: System Architecture, Business Fa? ADE, Business Logic, or even user interface, and for Data Storage, it may not require MDA intervention.
Imagine that o / r mapping provides mapping relationships, it is to separate RDBMS with other layers. If all it is in one place, it is not a burden on developers (sometimes automation is not necessarily, the better, the better) ?
Another point: ECO claims that "code / UML two-way synchronization", but does not guarantee "code / field can be different", which loses flexibility to some extent!
(Tip: "Synchronization" in UML means that the design is "consistent", but in O / R mapping, it does not require this "consistency", only need to establish a correspondence between Dal and Schema. Borland moved traditional modeling ideas into DAL design, the author considered debatable. In this regard, other O / R mapping schemes have done more nature, highlighting the meaning of "mapping", not just simple "Synchronization".)
Other
There are also some other technologies to implement O / R mapping or similar features. For some solutions to the author, Constructor, Grove is a good choice, constructor, "Model Driven Rad For .NET ", interested friends can visit the following sites:
http://www.dotnetbuilders.com
http://grove.911link.com
Said a lot, and it has come to the "Summary" time, the author is again bold advice: (1) Unlike the ADO.NET-based DAL implementation, O / R mapping has huge
Advantages, but also hide risk:
N The most serious problem is to conflict with the stored procedure!
As we all know, the essence of O / R mapping is a map, in this regard
Have a strict definition, is white, which is to convert table operation into object operation.
However, the flexibility of the stored procedure (incoming parameters, returning results, etc.) have to temporarily exclude outside the O / R mapping home (at least in the current,
The presentation of OJB, ObjectSpaces, etc.
On the other hand, if we want to achieve a more complex data logic, it is not
Do not write the original in new Object Language (such as: OCL, OQL, etc.)
This can be packaged in a complex SQL statement in the stored procedure. And even if I write
Out of these data logic, it will feel very ugly or even.
In the sense, this also violates the original intention of o / r mapping)!
n The second problem is: In the O / R mapping environment, the system's execution efficiency will have a certain loss, even if Cache Management (disposable load profile) or delayed loading (also known as lazy loading, only in access entity) When the class data is actually connected to the database) technology, since the Reflection mechanism is used to locate the entity class when the data is initially loaded (in some scenarios, the mapping relationship is reflected in the .NET Attribute mode, it is more time to take time) Fill data from ADO.NET is so fast!
If you think that the above risks are not a problem, the following is the truly advice of the author.
(2) ECO is a good choice in large-scale applications (generally referred to as enterprise-class applications); (3) If it is a normal N-Tier application, ObjectSpaces is full;
(4) Want to learn O / R mapping friends, you can take a look at the OPF / OJB source code, and the implementation of these two programs is similar to Eco / ObjectSpaces;
(5) If you do not want to use the ready-made O / R mapping, you can cut on demand on an OPF / OJB, or refer to the scenario proposed in "Designing your own persistence" below. U other
? ASTA
Network database application development or friends who have used Borland Midas technology should often be used under Delphi. It should not be unfamiliar with ASTA.
If ADO.NET or O / R mapping is implemented, DAL is Shaolin, Wudang's authentic heart method. The ASTA has a little bit of the taste of "Qiankun Migrant": Almost completely throw it almost completely from the DATA Access (And slightly different from the original place, but also count another moving J) to process!
The traditional DAL implementation is like this:
ASTA has another way, an additional "intermediate layer":
In general, the introduction of the intermediate layer is to improve flexibility, reduce coupling,
ASTA is designed with this feature.
A key point on the figure is between the Asta Client and Asta Server
The "network connection", ASTA technology is using network characteristics, indirectly
Block the difference between different database systems, so that the developer is finished when designing DAL
Needless to know the existence of Database! This situation is a bit like a browser, it is completely
Use the HTML page from IIS or apache, just know yourself
It is the HTML page to obtain the HTML page using the HTTP protocol!
In ASTA, the browser is Asta Client, the HTML page is Asta Dataset (which is different from the DataSet in ADO.NET, which can be considered to be another database independent data collection means), and IIS, Apache It is the different ASTA Server provided by ASTA (currently supporting most mainstream database systems, developers can also write their own ASTA Server), and HTTP protocol is naturally a communication protocol between Asta Client and ASTA Server! From a technical analysis, one of the purposes of ASTA architecture is to use its own protocol to block network communication protocols of different database systems, so that the client (DAL) completely gets rid of communication challenges when writing network database applications!
(The author remember, before .Net comes out, each time you write the Internet-oriented SQL Server application, in addition to configuring the connection string, you have to install the SQL Server Client Network Utility specially installed in the client to configure the Internet connection, do not say SQL The security issue caused by Server exposed port is that such a toss is also enough.
Write the program in ASTA is very comfortable, just know the address and port of ASTA Server, the username, password (ASTA comes with certification system, developers can also write their own Authentication / Authorization module, and even directly utilize databases The verification mechanism provided by the system), immediately obtain any data information of any database! Moreover, once the database system changes (such as switching from SQL Server to Oracle, the client does not require any modifications at all!
The lack of ASTA technology is also very obvious: due to the introduction of in some cases
(If the amount of data returns a large amount of data is enough to fatally "network intermediate layer",
When you develop large applications (especially enterprise-class applications for Internet)
It is necessary to be particularly careful, after all, comfortable to pay some costs!
Interested friends may wish to go to this website to see:
Http://www.astatech.com.com
? Net Remoting / WebServices
It is not ready to take the .NET Remoting / Webserve, after all, these two technologies are not done for DAL.
Helpless, it is to see some friends have been used, and later thinking, it is quite quite truth, and take it out to see you with you.
In fact, although Microsoft promotes XML WebServices, but in terms of technology, it can be discussed. NET Remoting, XML WebServices is nothing more than a special case of HTTP SOAP communication protocol in .NET Remoting.
.NET Remoting Apply to DAL may be due to two purposes:
(1) I want to achieve cross-platform data access, because DataSet in ADO.NET is sequentially, through Remoting or WebServices can restore site on the client;
(2) Alleviate server pressure and increase system flexibility.
This is a bit similar to the above ASTA technology, but only the agreement here.
Replace it to .NET Remoting Protocal. But use this way, or different from the flexibility of ASTA, after all, Remoting
Ask the client to register each DAL access interface, once the interface
Change, the interface must be registered!
Therefore, the author's suggestion is to avoid using .NET Remoting
Build the DAL module of the application (if it is business logic layer, no
There is this problem), unless it is really "forced" (for example: must be in DAL)
Layer implementation distributed computing or customer insist on using .NET Remoting J)!