NHibernate
Starting up with NHibernate
01 : Configuration
new Configuration().configure() can take a Dictionary object to which can be used to specify properties. Few of the important properties are discussed below
02 : Using override-able configurations
Mapping in NHibernate can be done using XML HBM mapping files, Using Fluent Mapping with AutoMapping and / or loquacious mapping. I tried defining AutoMapping conventions and configuring the Fluent NHibernate Configuration using these Conventions.
03 : Mapping using AutoPersistanceModel
I tried using Fluent mapping with autopersistancemodel. An instance of autopersistance is generated with details such as
Which classes to be mapping in NHibernate.
Conventions to be used
Location of assembly which can override these conventions
as
var autoPersistance = new AutoPersistenceModel()
.AddMappingsFromAssemblyOf<Product>()
.Conventions.Setup(c => c.Add<FluentAutoMappingConventions>())
.UseOverridesFromAssemblyOf<Product>()
.AddEntityAssembly(Assembly.GetAssembly(typeof(Product))).Where(entity => entity.GetInterfaces().Any(i => i == typeof(IEntity)));
Fluent Nhibernate consumes the autopersistance model as
return Fluently
.Configure(configuration)
.Mappings(x => x.AutoMappings.Add(autoPersistance))
.BuildConfiguration();
04 : Contextual Session
NHibernate provides a context based session. The current_session_context_class defines which implementation of ICurrentSessionContext to be used to define the current context.
sessionFactory.getCurrentSession() returns you a current session. It opens a new session or returns you the same session depending on the context.This wiki article discusses the property in more depth
web is the short name for using WebContextSession.
Important Pointers
working with QueryOver