On the. NET platform, there are many data persistence layer frameworks. This article briefly introduces the following types and recommends some learning resources:
1. nhib.pdf
2. nbear
3. Castle activerecord
4. ibatis. net
5. daab
Additional Introduction: dlinq
1. nhib.pdf
Speaking of nhib.pdf, I believe everyone is familiar with it. nhib.pdf comes from a very good Java-based hibernate relational persistence tool, which is persistent from the underlying database. net object to relational database, nhib.pdf for us to complete this, instead of writing SQL statements to operate on database objects, writeCodeOnly associated with objects, nhibernat automatically generates SQL statements and ensures that the objects are submitted to the correct tables and fields. manual use of SQL and ADO during development is greatly reduced. NET data processing time. nhib.pdf can help eliminate or wrap SQL code for a specific database and convert the result set from Table representation to a series of objects. Nhibernate uses XML file configuration. Each object class corresponds to a ing file, as shown in the following example:
Public class user
{
Public user ()
{
}
Private string ID;
Private string username;
Private string password;
Private string emailaddress;
Private datetime lastlogon;
Public String ID
{
Get {return ID ;}
Set {id = value ;}
}
Public String Username
{
Get {return username ;}
Set {username = value ;}
}
Public String Password
{
Get {return password ;}
Set {Password = value ;}
}
Public String emailaddress
{
Get {return emailaddress ;}
Set {emailaddress = value ;}
}
Public datetime lastlogon
{
Get {return lastlogon ;}
Set {lastlogon = value ;}
}
}
The. HBM. xml file corresponding to it is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.0">
<Class name = "nhibernatewebdemo. model. User, nhibernatewebdemo. Model" table = "users">
<ID name = "ID" column = "logonid" type = "string" length = "20">
<Generator class = "assigned"/>
</ID>
<Property name = "username" column = "name" type = "string" length = "40"/>
<Property name = "password" type = "string" length = "20"/>
<Property name = "emailaddress" type = "string" length = "40"/>
<Property name = "lastlogon" type = "datetime"/>
</Class>
</Hibernate-mapping>
Official homepage:Http://www.nhibernate.org/
Learning Resources
DDL blog in the garden:Http://www.cnblogs.com/renrenqq/, Including Chinese Translation of nhib.pdf documents and some excellent nhib.pdf written in DLLArticle.
Famous Zhang laosan:Http://blog.csdn.net/billy_zh/category/22383.aspx
Aero's nhib learning manual series:Http://www.cnblogs.com/chwkai/category/32514.html
The blog of the unintentional Liu is also worthy of recommendation:Http://www.cnblogs.com/9527/
Blog Park o/R Mapping Team:Http://www.cnblogs.com/team/ORMapping.html
Ii. nbear
Nbear developed by Teddy in garden is very familiar to everyone. Now the official version 3.0 has been released. Nbear includes not only the data persistence layer, but also IOC, distributed components, and Web components. Take a look at Teddy's introduction to nbear:
The core of nbear includes a generic, strong-type ORM Data Persistence interface, a set of related entity-related components, high-performance distributed components, and Web Components. Therefore:
1. nbear is most suitable for developing various Web Services Based on ASP. NET 2.0 and has high performance requirements.Program. Nbear. web components provide many components to accelerate web development. NET development efficiency is greatly improved. At the same time, simple and easy-to-use, outstanding performance of generic persistence support will enable you to focus more on business development, at the same time, there will be no performance problems and tedious configuration needs of traditional ORM Persistence frameworks (nbear almost does not require manual configuration, and performance is close to daab ).
2. High-Performance Distributed Components Based on MQ and. Net remoting make it easier for you to develop and maintain distributed programs. An application developed based on the nbear. IOC module can be a real load balancing distributed program without re-compilation.
3. for desktop applications, nbear is also a little learning curve (how many people will carefully study hibernate's reference manual to write a small calendar program ?) And practical and efficient data persistence solutions.
4. With nbearv3's comprehensive ORM support, more detailed documents and tutorials, and comprehensive code generation tools, nbear can also be used for enterprise-level program development.
Official homepage:Http://teddyma.cnblogs.com/articles/Ilungasoft_Framework.html
Learning Resources
The personal blog of Teddy is the first to learn resources:Http://www.cnblogs.com/teddyma/
Blog site Nb team:Http://nbteam.cnblogs.com/
Iii. Castle activerecord
Activerecord is a sub-project in Castle. The current version is RC1. It is also a very good persistent layer framework. It encapsulates Nhibernate at the underlying layer and uses attribute instead of the configuration file. This eliminates the need to write complex configuration files like Nhibernate. The following code snippet is shown:
[Activerecord ("users")]
Public class user: activerecordbase
{
Private int _ id;
Private string _ name;
Private string _ password;
Private string _ emailaddress;
Private datetime _ lastlogon;
[Primarykey (primarykeytype. Identity, "logonid")]
Public int ID
{
Get {return _ id ;}
Set {_ id = value ;}
}
[Property ("logonname")]
Public string name
{
Get {return _ name ;}
Set {_ name = value ;}
}
[Property ("password")]
Public String Password
{
Get {return _ password ;}
Set {_ password = value ;}
}
[Property ("emailaddress")]
Public String address
{
Get {return _ emailaddress ;}
Set {_ emailaddress = value ;}
}
[Property ("lastlogon")]
Public datetime lastlogon
{
Get {return _ lastlogon ;}
Set {_ lastlogon = value ;}
}
}
Official homepage:Http://www.castleproject.org
Learning Resources
Official documentation:Http://www.castleproject.org/activerec... tation/v1rc1/index.html
Ye's home:Http://wj.cnblogs.com/
Terrylee's castle development series:
Http://terrylee.cnblogs.com/archiv... astl_ioc_article.html
Ayende's blog, one of the members of the castle project:Http://www.ayende.com/Blog/
Iv. ibatis. net
Ibatis. net is divided into two parts: datamapper and dataaccess. It should be said that datamapper is the core of this framework. datamapper uses XML files to map entities to SQL statements. It is very simple to learn. After datamapper is used, we can freely use SQL statements or stored procedures. dataaccess allows us to operate data through a simple interface without having to understand the details of the underlying implementation. The following code snippet:
[Serializable]
Public class person
{
Private int ID;
Private string firstname;
Private string lastname;
Private datetime? Birthdate;
Private double? Weightinkilograms;
Private double? Heightinmeters;
Public Person (){}
Public int ID
{
Get {return ID ;}
Set {id = value ;}
}
Public String firstname
{
Get {return firstname ;}
Set {firstname = value ;}
}
Public String lastname
{
Get {return lastname ;}
Set {lastname = value ;}
}
Public datetime? Birthdate
{
Get {return birthdate ;}
Set {birthdate = value ;}
}
Public double? Weightinkilograms
{
Get {return weightinkilograms ;}
Set {weightinkilograms = value ;}
}
Public double? Heightinmeters
{
Get {return heightinmeters ;}
Set {heightinmeters = value ;}
}
}
The ing file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Sqlmap namespace = "person" xmlns ="Http://ibatis.apache.org/mapping"
Xmlns: xsi ="Http://www.w3.org/2001/XMLSchema-instance>
<Alias>
<Typealias alias = "person" type = "ibatisnetdemo. domain. Person, ibatisnetdemo"/>
</Alias>
<Resultmaps>
<Resultmap id = "selectallresult" class = "person">
<Result property = "ID" column = "per_id"/>
<Result property = "firstname" column = "per_first_name"/>
<Result property = "lastname" column = "per_last_name"/>
<Result property = "birthdate" column = "per_birth_date"/>
<Result property = "weightinkilograms" column = "per_weight_kg"/>
<Result property = "heightinmeters" column = "per_height_m"/>
</Resultmap>
</Resultmaps>
<Statements>
<Select id = "selectallperson" resultmap = "selectallresult">
Select
Per_id,
Per_first_name,
Per_last_name,
Per_birth_date,
Per_weight_kg,
Per_height_m
From person
</SELECT>
<Select id = "selectbypersonid" resultclass = "person" parameterclass = "int">
Select
Per_id,
Per_first_name,
Per_last_name,
Per_birth_date,
Per_weight_kg,
Per_height_m
From person
Where per_id = # value #
</SELECT>
<Insert id = "insertperson" parameterclass = "person">
<Selectkey property = "ID" type = "Post" resultclass = "int">
$ {Selectkey}
</Selectkey>
Insert into person
(Per_first_name,
Per_last_name,
Per_birth_date,
Per_weight_kg,
Per_height_m)
Values
(# Firstname #, # lastname #, # birthdate #, # weightinkilograms #, # heightinmeters #)
</Insert>
<Update id = "updateperson" parameterclass = "person">
<! [CDATA [update person set
Per_first_name = # firstname #,
Per_last_name = # lastname #,
Per_birth_date = # birthdate #,
Per_weight_kg = # weightinkilograms #,
Per_height_m = # heightinmeters #
Where
Per_id = # ID #]>
</Update>
<Delete id = "deleteperson" parameterclass = "person">
Delete from person
Where
Per_id = # ID #
</Delete>
</Statements>
</Sqlmap>
Official homepage:Http://ibatis.apache.org/
Learning Resources
Official documentation:
Http://opensource.atlassian.com/confluen... ibatis/quick + start + Guide
Shanyou's ibatis. Net Development Guide series:
Http://www.cnblogs.com/shanyou/archive/2006/04/29/388610.html
5. daab
Daab is an Application Block in the Microsoft Enterprise Library. It can help us achieve universal data access, so we will also introduce it here. Daab enables data access in applications without knowing the specific database system. I believe many of my friends are familiar with daab and have been used in projects, look at a simple code snippet:
Public String getcustomerlist ()
{
// Create a database object
Database DB = databasefactory. createdatabase ();
// Create a dbcommand object using SQL statements
String sqlcommand = "select customerid, name, address, city, country, postalcode" +
"From MERs ";
Dbcommand = dB. getsqlstringcommand (sqlcommand );
Stringbuilder readerdata = new stringbuilder ();
// Call the executereader Method
Using (idatareader datareader = dB. executereader (dbcommand ))
{
While (datareader. Read ())
{
// Get the value of the 'name' column in The datareader
Readerdata. append (datareader ["name"]);
Readerdata. append (environment. newline );
}
}
Return readerdata. tostring ();
}
Official homepage:Http://msdn.microsoft.com/practices/
Learning Resources
Enterprise help documentation and hands on Lab
Terrylee's Enterprise Library series:Http://www.cnblogs.com/Terrylee/archi... nterprise_library.html
Additional Introduction: dlinq
Although dlinq is not an open-source framework, it is better to mention the persistence of data. dlinq is the next-generation database integration Query Language of Microsoft. Before that, Microsoft tried objectspace and finally it was gone. Dlinq is implemented in a way similar to activerecord mentioned earlier. It does not support external xml configuration files, but uses attribute, as shown in the following code snippet:
[Table (name = "MERs")]
Public Class Customer
{
[Column (ID = true)]
Public String customerid;
[Column]
Public String city;
}
Official homepage:Http://msdn.microsoft.com/netframework/future/linq/
Learning Resources
Download the LINQ may CTP version:Http://msdn.microsoft.com/data/ref/linq/
Scottgu's blog:Http://weblogs.asp.net/scottgu/default.aspx
Finally, it is worth mentioning that Microsoft has launched an ado.net vnext, which uses a ing file for configuration, and is more similar to nhib.pdf. There are many more persistent layer frameworks, such as Grove.