On the. NET platform, there are many data persistence layer frameworks. This article mainly 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 not looking at 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 does this for us, instead of writing SQL statements to manipulate database objects. The code written only associates with objects. nhibernat automatically generates SQL statements, make sure that the object is submitted to an accurate table and field. manual use of SQL and ADO during development is greatly reduced. NET data processing time. nhib.pdf can 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: Comment.
Famous Zhang laosan: http://blog.csdn.net/billy_zh/category/22383.aspx
Aero's Nhibernate learning manual series: http://www.cnblogs.com/chwkai/category/32514.html
Unintentional Liu's blog is also very recommended: http://www.cnblogs.com/9527/
Blog Park o/R Mapping Team: http://www.cnblogs.com/team/ORMapping.html
Ii. nbear
Everyone knows about nbear developed by Teddy in garden. 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 group of related entity-related components, high-performance distributed components, and Web Components. Therefore:
1. nbear is most suitable for developing various web programs based on ASP. NET 2.0 and has high functional requirements. Nbear. web components provide many components to accelerate web development. NET development efficiency has been greatly improved. At the same time, simple and easy-to-use, scalable generic persistence support will enable you to focus more on business development, at the same time, there will be no functional questions and complicated configuration needs of the traditional ORM persistence framework (nbear almost does not require manual configuration, and the function 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. Along with nbearv3's comprehensive ORM support, more specific documents and tutorials, and comprehensive nbear tools, nbear can also be used for enterprise-level program development.
Http://teddyma.cnblogs.com/articles/Ilungasoft_Framework.html
Learning Resources
Learning Resources of course the first teddy personal blog: 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 documents: http://www.castleproject.org/activerec... tation/v1rc1/index.html
Leaf home: http://wj.cnblogs.com/
Terrylee's castle development series:
Http://terrylee.cnblogs.com/archiv... astl_ioc_article.html
Blog of ayende, one of the castle project members: http://www.ayende.com/Blog/
Iv. ibatis. net
Ibatis. net is divided into two departments: datamapper and dataaccess. 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 manipulate 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 implement universal data access, so we will also describe it here. Daab enables data access in applications without knowing the detailed 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 cannot be regarded as 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 http://msdn.microsoft.com/data/ref/linq/ for LINQ may CTP
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.