Using FLUENT Nhibernate in spring. Net automap Automatic Map

Source: Internet
Author: User
Tags automap
Using FLUENT Nhibernate in spring. net

 

Http://blog.bennymichielsen.be/2009/01/04/using-fluent-nhibernate-in-spring-net/

 

 

Protected Override Void Postprocessconfiguration (configuration config)
{
Base . Postprocessconfiguration (config );

Fluently. Configure (config)
. Database (mysqlconfiguration. Standard. connectionstring (
C => C. fromconnectionstringwithkey ("connectionstring ")))
. Mappings (M => M. fluentmappings
. Addfromassemblyof ())
. Buildsessionfactory ();
}

 

 

 

Protected Override Isessionfactory newsessionfactory (configuration config)
{
Config = fluently. Configure (config)
. Mappings (M => M. fluentmappings. addfromassemblyof ())
. Buildconfiguration ();
Return Base . Newsessionfactory (config );
}

 

Here Is The implementation If You are Using Fluentnhibernate auto mapping:

Protected Override VoidPostprocessconfiguration (configuration config)
{
Base. Postprocessconfiguration (config );

VaRAutomappingcfg =NewAutomappingconfiguration ();

VaRAutomap = automap. assemblyof (automappingcfg)
. Conventions. Add (defaultcascade. All (), defaultlazy. Never ())
. Conventions. Add ()
. Override (MAP =>{ map. ignoreproperty (I => I. Total );});

Fluently. Configure (config)
. Mappings (M => M. automappings. Add (automap ))
. Buildconfiguration ();
}

InOutmapping you don't need to inject fluentnhibernatemappingassemblies. So configure sping. Net accordingly

 

 

 

Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using Spring. Data. nhib.pdf;
Using Fluentnhib.pdf;
Using System. reflection;
Using Nhib.pdf. cfg;

Namespace Sessionfactories
{
Public Class Fluentnhibernatelocalsessionfactoryobject
: Localsessionfactoryobject
{
///   <Summary>
/// Sets the assemblies to load that contain fluent nhib1_mappings.
///   </Summary>
///   <Value> The mapping assemblies. </Value>
Public String [] Fluentnhibernatemappingassemblies
{
Get ;
Set ;
}

Protected Override Void Postprocessconfiguration (configuration config)
{
Base . Postprocessconfiguration (config );
If (Fluentnhibernatemappingassemblies! = Null )
{
Foreach ( String Assemblyname In Fluentnhibernatemappingassemblies)
{
Config. addmappingsfromassembly (assembly. Load (assemblyname ));
}
}
}
}
}

 

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.