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 ));
}
}
}
}
}