NHibernate version 3 new features

Source: Internet
Author: User

Configuration section

Two new loquacious-configuration modes in the configuration section: stream Configuration (fluent-configuration) and lambda expression configuration (lambda-configuration) .

fluent-configuration , as the name implies, uses the fluent API to configure sessionfactory properties, providing strong type support, compile-time error checking, and so on. You can learn more by Sessionfactory fluent configuration. For example, use the flow configuration method to configure the NHibernate minimum:

var  configure = new  configuration  (); configure. Sessionfactory (). Named ( "Demo" ). Proxy.through<proxyfactoryfactory  > (). Integrate. Using<mssql2008dialect  > (). Connected. Using ( "ConnectionString" ); 

lambda-configuration is configured Methods properties with the c#3.0 extension method (Extension sessionfactory). You can learn more by configuring the Sessionfactory lambda configuration and the cache lambda-configuration configuration. For example, use a lambda expression to configure the minimum nhibernate:

var  configure = new  configuration  (); configure. Sessionfactoryname (); configure. Proxy (p = P.proxyfactoryfactory<proxyfactoryfactory  > ()); Configure. Databaseintegration (DB =>{db.    Dialect<mssql2008dialect  > (); Db.    Driver<sqlclientdriver  > (); Db. ConnectionString = ConnectionString;}); 

The new Wcfoperationsessioncontext class provides support for the WCF environment, and we directly configure "Current_session_context_class" to "wcf_operation" Apply NHibernate in a WCF environment.

Mapping part

For the mapping section, Fabio Maulo completely reconstructs the NHibernate.Cfg.MappingSchema Code section, improving performance. At the same time, NHibernate designed a configuration ORM tool--conform: Parse domain structure, generate hbmmapping class according to pattern adapter and custom configuration, Avoid nhibernate the process of generating hbmmapping classes by reading XML map file deserialization. However, conform is not part of the nhibernate and needs to be downloaded separately. Li Yongjing introduced this tool in his blog, and can refer to conform overview, Principles, Onetoone semantics, manytomany semantics, and component semantics. We can use this:

var  orm = new  Span style= "Color:rgb (43,145,175)" >objectrelationalmapper  (); Orm. Tableperclass<domain  > (); var  mapper = new  mapper  (ORM); var  hbmmapping= mapper. Compilemappingfor (new  [] {typeof  (domain )}); 

The adddeserializedmapping(hbmmapping mappingdocument, String documentfilename) method is added to the configuration class, You can parse hbmmapping directly so that you choose not to use an XML file but conform. For example, the hbmmapping generated using conform above is added to the configuration:

conf=Configuration(); //... "Domain");
Query section

In the NHibernate 3.0.0 release, query mode has added the LINQ support and the strongly typed query API (queryover) two kinds of queries.

Queryover is a conditional (criteria) query for lambda expressions that is readable and supports the property-renaming feature. Refer to Queryover in NH 3.0. For example, the following query name is Li Yongjing, the person collection in descending order of age:

var  query = S.queryover<person  > (). Where (p = = P.name = =  "Li Yongjing" ). (p = p.age). Asc. List (); 

LINQ Provider implementations based on the HQL AST parser, developed by the Steve Strong contributor, use a third-party RE-LINQ open source framework at the bottom. However, the LINQ query provided by the NHibernate3.0.0 version is still in the Bate phase, and Fabio Maulo is ready to release version 3.1 to fix the LINQ query bug. You can refer to: NHIBERNATE.LINQ standard queries, enhanced queries, custom extensions. We use the query<t> () extension method of the ISession interface to create a nhibernate.linq query.

query = Session. query<person"Li Yongjing"). ToList ();
Other

There are some other new features:

Refactoring Logging Abstraction Log System module: Remove the dependency on the Log4net.dll assembly, now available with commonlogging or Nlog log system. You can refer to using NLog via common.logging with NHibernate.

attribute delay loading and No proxy correlation Characteristics: Specific Use methods can refer to Ayende nhibernate new Feature:lazy properties and nhibernate new Feature:no Proxy Associations two blog posts. It only supports Castle Bytecode-providers, spring.net and LINFU proxies are not supported.

Mappings support XDocument, System.Uri, XmlDoc, Local & UTC datetime types.

Bytecode-providers Assembly Update: Castle uses the official version of 2.5.2, which was released on November 15, 2010, which is the Castle.Core.dll assembly. Liufu uses version 1.04, the LinFu.DynamicProxy.dll assembly, released on April 5, 2010.

Change

If you upgrade from the NHibernate2.1.2 version to the NHibernate3.0.0 version, you need to be aware of the following changes:

    1. NHibernate3.0.0 version does not support. Net3.5 The following versions, that is, the. Net2.0 version, cannot be upgraded to the NHibernate3.0.0 version.
    2. [NH-2392] Icompositeusertype.nullsafeset method signature changed.
    3. [Null values in Nh-2199]maps/dictionaries are no longer silently ignored/deleted.
    4. [NH-1894] Sybaseanywheredialect deleted and replaced with Sybaseasa9dialect. The Sybase Adaptive Server Enterprise (ASE) dialect was deleted.
    5. [NH-2251] Changes in the getlimitstring signature in dialect.
    6. [NH-2284] deleted obsolete members.
    7. [NH-2358] The DateTimeOffset type is now no longer an alternative to DateTime.
Utility Tools

In the last year, there have been some excellent nhibernate tools on the Web:

    1. HQL Language Service for Visual Studio: Provides smart hints and syntax validation checks for us to write HQL queries.
    2. NHibernate Profile: Visual NHibernate Performance Detection optimization tool.
    3. Visual NHibernate: visual design and Mapping tools.
    4. Mindscape NHibernate Designer:vs Design tool, similar to the EF designer.

where HQL Language Service for Visual Studio is an open source tool, the others are commercial versions.

Copyright NOTICE: This article for Bo Master http://www.zuiniusn.com original article, without Bo Master permission not reproduced.

NHibernate version 3 new features

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.