110 likes | 289 Views
A blitz through NHibernate. Introduction. Who I am What is NHibernate ? Object Relational Mapper A framework for building advanced frameworks Ported from Java A wide NHibernate ecosystem now exists Why ORMs?. Simple NHibernate example. Download and add necessaryreferences
E N D
Introduction • Who I am • What is NHibernate? • Object Relational Mapper • A framework for building advanced frameworks • Ported from Java • A wide NHibernate ecosystem now exists • Why ORMs?
Simple NHibernate example • Download and add necessaryreferences • Intellisense • Show common exceptions • Configure mapping files • Configure configuration files • Create repository
Custom defined mappings NHibernate API ICompositeUserType Core API IUserType Configuration Instrumentation Statistics ISessionFactory Interception IEventListener ISession IInterceptor Querying ITransaction IQuery ICriteria
A more complex mapping • Many-to-one • Cascading • One-to-many • Components • Assigned keys
Mapping class inheritence • Table per class hierarchy • One table represents an aggregate • Simple and good performance wise • Loss of not-null constraints • Table per concrete class • One table for each non-abstract class • Can be problematic for polymorphic queries • Table per subclass • Completely normalised • Polymorphic queries possible
Customisation • NamingStrategy • IUserType • ICompositeUserType • Should be an exception more that the rule
Interception • Event listeners • Interceptors • Refer to empty interceptor implementation • Refer to profiler interceptor setting
Querying • HQL • ICriteria API • Query By Example (QBE) • Linq to NHibernate • Straight SQL
Statistics • New feature added at NHibernate 2.0 • Exists at both SessionFactory and Session • Must turn statistics on, off by default • Refer to SessionFactoryStatisticsBuilder
Caching • First level Caching • Default caching level • Caching at the session level • Second level Caching • Must be configured at Configuration and entity itself • Caching at the session factory level • Providers such as memcached, nvelocity supported