What kind of ORM framework do we need?

Source: Internet
Author: User

Recently in the research of ORM, what kind of framework is what we want

The significance of the development framework is

    • Develop more standard, more unified, not because different people write code is not the same
    • More efficient development, no need to reinvent the wheel, duplicate useless code, and streamline the development process
    • The operation efficiency is controlled, and the program stability has been improved.

The framework of the online attention more than search, made a list

    1. Nhibernate
      Hibernate from Java
      Reference: http://www.cnblogs.com/ylwn817/articles/1963528.html
    2. Entity Framework
      Microsoft's framework, are more familiar with
    3. Ibatis.net
      Apache Open Source Project
      Reference: http://developer.51cto.com/art/200907/137796.htm
    4. Nbear
      Blog Park Teddy Development Project
      Reference: http://www.cnblogs.com/teddyma/archive/2006/11/07/553562.html
    5. Castle ActiveRecord
      ActiveRecord is an extension of hibernate
      Reference: http://terrylee.cnblogs.com/archive/2006/04/03/365762.html

Plus some of the frameworks written by others, including the self-written, the big difference is not bad

Sort out some of the common features and make a score on these frames

    1. Programmability (Syntax support) we want to stop stitching SQL in the form of strings and compile validation
    2. fault tolerance can be seen as the above expansion, do not want a place to change, other places have not changed, no hint, causing errors
    3. Development Efficiency includes the configuration of the framework, the development process
    4. Correlated query Support correlation query is unavoidable
    5. additional configuration is no need for additional configuration and third-party tool support, affecting development efficiency
    6. Cache support can greatly enhance program efficiency

Dealing with the database, the most important function when the query, the query does not directly affect the ease of use, Lambda and LINQ mode is preferred

The following is an analysis of these frameworks, which are not carefully studied, may not be correct, represent only personal opinions, for informational purposes only

Nhibernate

New nhibernate adds lambda and LINQ query support

Join seems to be possible.

var list1 = session. Createcriteria<product> ()    . ADD (Restrictions.eq ("discontinued", false))    . ADD (Restrictions.eq ("Category.id", 2))    . List<product> ();

There are also several implementations for caching support
Http://www.cnblogs.com/lyj/archive/2008/11/28/1343418.html

Just as always, you need to configure XML mappings

Entity Framework

In the above features, in addition to no cache, EF is perfect, off and in the latest version 7, forced the Codefirst mode, is not the other framework (so more in line with the business development model)

Some say that EF is too large, the use of bad efficiency will be some problems, indeed, especially the association, write poorly on the SQL statement to make inefficient, this is also his programmability is too strong, if not so strong, will not be so written, will think of the structure of a good design design

Bulk Update/delete is not supported by default due to too much object concept

Ibatis.net

In addition to having basic object mapping benefits that are only flexible enough to describe, all operations require a configuration XML file to represent

﹤select id= "Getallaccountsashashmapviaresultmap"                 resultmap= "Account-hashtable-result" >      select *      from Accounts      ORDER BY account_id  

It seems to also support caching

﹤select id= "Getcachedaccountsviaresultmap"             resultmap= "Account-result" cachemodel=             "Account-cache" >      SELECT * FROM      Accounts      ORDER by account_id  

This is no longer object-oriented, it is a query map

Nbear

Nbear can automatically map object associations by object, but cannot directly correlate queries
Conditional query, parameterization, not too smart, like a long time not updated, I do not know how to check now

localuser[] users = gateway. Select<localuser> (_entity.localuser.id > 5 | _entity.localuser.loginid = = "Teddy", _entity.localuser.id.desc & _ENTITY.LOCALUSER.LOGINID.ASC);

  

Caching can be supported in a configurable way, as if it were only a single table

<cacheconfig enable= "true" >    <cachingTables>      <add key= "Northwind.orders" value= "5"/>    </cachingTables> </cacheConfig>

In addition to table mapping, also supports the view, stored procedure mapping, (this is actually out of the concept of object-oriented, well-designed business objects, there is no need for this basic)
Object definition is an interface type and does not understand

public interface Identableentity:ientity {[PrimaryKey] int Id {get; set;}       String Name {get; set;} }

  

Castle ActiveRecord

ActiveRecord extended to hibernate, with a bunch of database configurations

Associative objects are also supported, through property definitions

  [Hasmany (typeof (Post), table= "posts", columnkey= "Post_blogid")]    Public IList Posts    {        get {return _posts;}        set {_posts = value;}    }

Query method for methods to pass parameters, compared to the original, do not know the latest not introduced LINQ and Lambda
Http://terrylee.cnblogs.com/archive/2006/04/12/372823.html

SimpleQuery query = new SimpleQuery (
typeof (Post), typeof (int),
@ "Select Post. Id from Post post where post. Created between? and? ",
Start,end
);

Combine

Programmability (Syntax support) Fault tolerance Development efficiency Correlation Query Support Degree Additional configuration Cache support
Nhibernate LINQ&LAMBDA syntax High In In mapping requires configuration XML Support
Entity Framework LINQ&LAMBDA syntax High High High Not supported
Ibatis.net No Low Low High XML Configuration Query Support
Nbear Operator overloading High In In Requires tools to generate classes Support
Castle ActiveRecord No Low In In Support
Inquire

When designing an ORM framework, it is possible to indicate that the query is generally divided into several situations

    • Implement LINQ&LAMBDA syntax sugar, with the help of. NET Framework Implementation expression parsing
    • Self-written expressions to achieve a similar effect (at the cost of generating a bunch of proxy classes with tools, many of which are developed by a framework that has this disadvantage)
    • Operations such as. Bigthan ("number", ">10") are too complex, have poor programmability, and are low in fault tolerance by means of methods
    • Direct SQL can cause programmability and low fault tolerance

The best way to see it is LINQ and Lambda.

Update

Ideally, which property of an object has been modified, which database will be updated to the following design

    1. Make a fuss over the property set method, in order to change the value to know which property has been changed, and to determine the update as
      Cost: The Set method needs to be modified in large quantities or generated with a template (EF7 seems to have solved the problem)
    2. parameter of the parameter is assigned, the disadvantage is not too smart, the programmability is not high tolerance
Extended Support, caching

The development of efficient applications without the support of the cache, data can not always be read from the database, or always do not have to shut down to obtain data

Cache creation, expiration processing, and lookup efficiency also need to be considered, such as NHibernate and Nbear must first be configured to cache, simple values can not tolerate

Codefirst Or Dbfirst

Also mentioned above, EF7 forced the Codefirst model, the development concept to change, first business data, data is based on business implementation, ideally

What kind of business structure, should have what kind of data table structure, should not go to tube database what kind of, by the framework to deal with the line, such as automatic mapping, automatically create maintenance database

That's the structure of the object to be finished with an XML data table mapping file, to be dragged out to shoot for 10 minutes

Ease of development

A lot of frameworks need tools to generate a bunch of proxy classes, add attributes/fields, and regenerate them again, so the convenience is very low, like a car before running to warm up for 10 minutes, it is very anxious

The above is only a personal point of view, the wrong place please testify

What kind of ORM framework do we need?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.