Starting NHibernate | Adding DLLs
March 30, 2010
I am now going to spend a little time discussing the core DLL structure that you will need to start your project and the NHibernate configuration file. Let’s get you started!
First, you will need to create your Solution (then you can add a “Domain” Project to it), you will need to reference the NHibernate DLLs listed below in your main project. What I like to do with my DLLs, is create a lib folder in the solution root folder (not included into the project), and place all my DLLs and their resources there. This keeps me organized and organization is keen, when your creating a large solution.
Download: http://sourceforge.net/projects/nhibernate/files
In reality “NHibernate” exists in the NHibernate.dll and nothing more. However, there are many components to it for example for example, lazy loading for NHibernate references the Castle project DLLs and therefor we add those DLLs to our solution. Don’t get bogged down by the amount of files, keeping code separate for reuse is what OOP is all about. For now lets add:
- NHibernate.dll
- NHibernate.ByteCode.Castle.dll
- log4net.dll
- Iesi.Collections.dll
- Antlr3.Runtime.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
You will also need to include the following files, with the DLLS:
- log4net.license
- log4net.xml
- Nhibernate.xml
And I recommend adding “NHibernate.Linq.dll” a separate download for Linq support.
When you have all of these files referenced, we can go onto setting up the connection, information. NHibernate provides you with two files named: “nhibernate-mapping.xsd” and “nhibernate-configuration.xsd” along side with their DLLs. These are mapping files, you don’t need them but they are very helpful for writing a lot of nhibernate xml based files which we will go into later on. We will need to create an “nhibernate.config” file now though, so lets do this first:
NHibernate.Dialect.MsSql2005Dialect NHibernate.Connection.DriverConnectionProvider NHibernate.Driver.SqlClientDriver 16 web NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle [CONNECTIONSTRINGNAME]
Notice: [APPSESSIONNAME], [CONNECTIONSTRINGNAME], and [MAPPINGASSEMBLYNAME].
You will need to replace [APPSESSIONNAME] with the name of your session factory (a manager for your session), usually developers will use the Project/Solution name since the session factory is for the particular solution and since their is usually one session factory per solution you don’t reference the name of the session factory much. Note: it is possible to have multiple session factories but that’s another whole can of worms we will not go into for now.
The [CONNECTIONSTRINGNAME] should be the name of your connection string in either App.config or Web.config which looks similar to this:
Finally, the [MAPPINGASSEMBLYNAME] should be your Domain project, which I talked about earlier. Now this can be the same project but usually it is where your Domain objects live.
PART TWO: Starting NHibernate – Mapping Tables to Objects
What do you think?










will you continue? waiting for you
Comment by msony — April 21, 2010 @ 4:38 am
Sorry, for taking so long, we have had a lot of work at the office, I will try to put something together soon for you.
Comment by Andrew Kharlamov — April 21, 2010 @ 12:15 pm
Alright, here is a fast write up on part 2 Mapping Tables
http://cowfarm.net/249/starting-nhibernate-mapping-tables-to-objects/
Comment by Andrew Kharlamov — April 21, 2010 @ 3:13 pm
Ping Back [...] Part one: Starting NHibernate – Adding DLLs [...]
Pingback by Starting NHibernate | Mapping Tables to Objects « CowFarm.NET — April 21, 2010 @ 3:17 pm