Astute developers would immediately jump to the conclusion that this identifier must be related to PRIMARY KEY because i said " unambiguously identify a single row in a database table". So every object will have a separate identity assigned to it, which is stored as a property in it and mapped in NHibernate mapping file using the keyword.
What this means in plain words is that ORM software should know, to what row in a database table the object maps to without ambiguity (Though this statement is more applicable to object-relation mappings using Row Gateway pattern, we will not get into that discussion here.).
Object Identity is important for all ORM systems including NHibernate because when a CLR loaded object is modified, an ORM software must know without ambiguity to which particular row in the database table the changes must be made persistent by using DML sql statements which are generated automatically for every unit of action performed in the object (object creation & save=insert statement, object modification = update statement, object deletion = delete statement). Hopefully you have read the article given in Pre-Requisites section posted on the official NHibernate site blogs and tried it because its the best introduction to NHibernate.įundamental starting point in developing / consuming ORM software is fixing the identity of object. Using the code And Using NHibernate For One-To-One Mapping Read through Article 1- 5 as they have the code samples embeded in figures in the article with explanations.
In Articles 1-5, I have embedded the NHibernate and C# code for establishing the associations from the sample project of Article 7 in the article itself with explanations and figures, to show how to map the various associations in Nhibernate. Since its console based, it will have only pocos.
In articles 1 - 5, we will work towards evolving the various object associations for the full sample of Article 7. Examples of all articles are based in this ECommerce scenario. + MICROSOFT VISUAL STUDIO 2012 PROFESSIONAL TRIAL VERSION HAS BEEN USED FOR ALL SAMPLES HERE.Īrticle 7 contains a downloadable console based project of the ECommerce application scenario (simple pocos, just to give the idea of association in an easy to understand way). The change in the visual studio setup between the article link above and sample project available for download in Article 7 is that here we use SQLSERVER DB instead of SQL SERVER Compact Edition and choose "SERVICE BASED DATABASE" option while adding the database. TO READ MY ARTICLE SERIES, IT IS AN ABSOLUTE PREREQUISITE THAT YOU FOLLOW THE LINK ABOVE AND SETUP THE PROJECT IN VISUAL STUDIO ACCORDING TO GUIDELINES GIVEN IN IT FOR NHIBERNATE USE. The above mentioned tutorial is OFFICIAL AND THE BEST INTRODUCTION TO SETTING UP NHibernate in VISUAL STUDIO and to jumpstart to NHibernate. Backgroundīefore embarking on reading this article series on NHibernate, please read this tutorial in NHibernate page But if a requirement for NHibernate existsĪnd you are new to ORM and NHibernate, then this 8 part article series may be useful to you. That said, unless there is a strategic or systems requirements demanding NHibernate usage, Language Integrated Query should be the chosen path in c#. For strategic thinking resource managers and pocos inclined architects, NHibernate offers other unique advantages they are very well aware of and needs no introductions from me. This adds huge advantages for domain classes reuse, unit testing and test driven development. If coded correctly all POCOs (PLAIN OLD CLR OBJECTS) are guaranteed to be free from persistence and transaction concerns. There is zero leakage of concerns when NHibernate is used correctly for persistence.
Both SPRING.NET and CASTLE WINDSOR, two of the oldest DI containers, have extensive support for NHibernate. There are scenarios where NHibernate is an useful addition. For object relational mapping in a rapid application development setup using c#, the default choice is Language Integrated Query and the other main option is NHibernate.