What ORM Framework do we need for ORM?

Source: Internet
Author: User

Recently in the study 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. Correlation query Support degree correlation query is unavoidable
    5. Additional configuration and third-party tooling support to affect 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.

1234 varlist1 = 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

123456 selectid="GetAllAccountsAsHashMapViaResultMap"                resultMap="account-hashtable-result"﹥     select    fromAccounts     order byAccount_ID ﹤/select

It seems to also support caching

1234567 selectid="GetCachedAccountsViaResultMap"            resultMap="account-result"            cacheModel="account-cache"﹥     select    fromAccounts     order byAccount_ID ﹤/select

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

1 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

12345 <cacheconfig enable= > &NBSP;&NBSP;&NBSP;&NBSP; <cachingtables> &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <add key= "northwind.orders"   value= "5"  /> &NBSP;&NBSP;&NBSP;&NBSP; </CACHINGTABLES> &NBSP; </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

1234567891011 publicinterfaceIdentableEntity : IEntity       {           [PrimaryKey]           intId { getset; }           stringName { getset; }       }

  

Castle ActiveRecord

ActiveRecord extended to hibernate, with a bunch of database configurations

Associative objects are also supported, through property definitions

1234567891011 [HasMany(typeof(Post), Table="posts", ColumnKey="post_blogid")]  publicIList 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

1 SimpleQuery query = newSimpleQuery(
1             typeof(Post),typeof(int),
1            @"select post.Id from Post post where post.Created between ? and ?",
1             start,end
1             );

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
    3. Using the AOP message broker to intercept attribute changes is too inefficient and cannot be debugged
Performance, caching

Although it is very rare to see the Web server CPU consumption is very high, but the operational efficiency still needs to be considered, the running logic judgment time directly affects the request response time, in the ORM framework

This time is much consumed in the type and data mapping, to reduce response time, need to optimize the mapping behavior, reduce unnecessary computation

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

Generic type problem: When working with data, some must carry a generic type, so that it feels like a tail on development, very redundant, inconvenient

Multiple database/docu support

Multi-Library support is unavoidable, which means that the framework can be configured by business which library to use

In the framework design, the basic will consider a variety of database support, if it is a variety of database multi-Library ...

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

What ORM Framework do we need for ORM?

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.