NHibernate3 anatomy: Configuration of Sessionfactory Lambda

Source: Internet
Author: User

Overview

In NHibernate3.0, the properties and cache configurations of Sessionfactory implement stream configuration (fluent-configuration) and lambda expression configuration (lambda-configuration )。 NHIBERNATE3.0 has added NHibernate.Cfg.Loquacious to this namespace. Added strong type configuration support for us. The previous article introduced the Flow configuration (fluent-configuration), do not know, please stop here to see the previous specific implementation. This article describes the implementation of lambda expression configuration (lambda-configuration).

Lambda expression configuration (lambda-configuration)

The lambda expression configuration (lambda-configuration) method is implemented using the c#3.0 extension method (Extension Methods), NHibernate contributor (Fabio Maulo) Write these extension methods in the Configurationextensions static class. Some of the following extension methods (Extension Methods) are now implemented.

Sessionfactory Basic Settings

In the Configurationextensions extension method:

The Sessionfactoryname () extension method is used to set the sessionfactory name.

The hqlquerytranslator<tquerytranslator> () extension method is used to set the "Query.factory_class" property.

Database Configuration (databaseintegration)

The Databaseintegration extension method is used to set the database configuration.

//code Snippets Copyright http://lyj.cnblogs.com/Cfg. Databaseintegration (db = {db). dialect<Mssql2005dialect> (); Db. Keywordsautoimport =Hbm2ddlkeywords.                      AutoQuote; Db. Logsqlinconsole =true; Db. Logformatedsql =true; Db. connectionprovider<Debugconnectionprovider> (); Db. driver<Sqlclientdriver> (); Db. IsolationLevel =IsolationLevel.                      readcommitted; Db. Connectionreleasemode =Connectionreleasemode.                      Aftertransaction; Db. ConnectionString ="The connection string"; Db. batcher<sqlclientbatchingbatcherfactory> (); Db.                      BatchSize = 15; Db. Preparecommands =true; Db.                      Timeout = 10; Db. exceptionconverter<Sqlstateconverter> (); Db. Autocommentsql =true; Db. Hqltosqlsubstitutions ="True 1, False 0, yes ' Y ', no ' N '"; Db.                      maximumdepthofouterjoinfetching = 11; Db. Schemaaction =schemaautoaction.                  Validate; });
Caching configuration (cache)

The cache extension method is used to configure the NHibernate level two cache to see the full implementation:

//Code Snippets Copyright http://lyj.cnblogs.com/ cfg.                    Cache (c + = {c.useminimalputs = true ;                    C.regionsprefix =  "XYZ" ;                    C.defaultexpiration = 15;                    C.provider<hashtablecacheprovider  > ();                C.querycache<standardquerycache  > (); });

There is also a entitycache extension method for the domain entity to set level two cache, the next article is described in detail.

Agent configuration (proxy)

The proxy extension method is used to configure the NHibernate lazy-loaded bytecode provider, NHibernate provides three kinds of adapters configured by the framework proxy, respectively, NHibernate.ByteCode.Castle.dll, NHibernate.ByteCode.Spring.dll, NHibernate.ByteCode.LinFu.dll. Complete implementation:

//Code Snippets Copyright http://lyj.cnblogs.com/ cfg.                    Proxy (P = = {p.validation = false ; P.proxyfactoryfactory<nhibernate.bytecode.linfu.                proxyfactoryfactory  > (); });

To take a closer look, we can set the two properties of validation and proxyfactoryfactory, NHibernate according to our settings put "Environment.useproxyvalidator" namely "Use_proxy_ Validator "assignment. Similarly, "Environment.proxyfactoryfactoryclass" is "Proxyfactory.factory_class".

Collection Factory configuration (collectiontypefactory)

The previous article has a specific introduction

Simple notation:

//Code Snippets Copyright http://lyj.cnblogs.com/cfg.CollectionTypeFactory<DefaultCollectionTypeFactory>();
Mapping Configuration (Mappings)

Simple notation:

//Code Snippets Copyright http://lyj.cnblogs.com/cfg.Mappings(m=>                   {                       "MyCatalog";                       "MySche";                   });
Conclusion

In NHibernate3.0, NHibernate contributors (Fabio Maulo) Use c#3.0 extension methods (Extension Methods), lambda expressions (lambda expression), and recently popular fluent interfaces (Fluent Interface) implemented the Sessionfactory strongly typed properties property configuration.

Through the introduction of these two articles, I believe you have some understanding.

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

NHibernate3 anatomy: Configuration of Sessionfactory Lambda

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.