Click here to Skip to main content
Click here to Skip to main content
Go to top

Using Nhibernate in SharePoint 2010

, 17 Nov 2013
Rate this:
Please Sign up or sign in to vote.
Guide for how to run Nhibernate on Sharepoint 2010

Introduction

Running Nhibernate on Sharepoint is not an easy task. It might take 1 or 2 days to do it. In this tutorial, I will try to make this task easy by providing a step by step guide starting from how to download NHibernate to how to configure it on SharePoint.

You can download the latest Nhibernate version from here.

In my tutorial, I am assuming that you know what’s NHibernate and how to use it, if it’s the first time you hear about NHibernate, please read the following tutorial first:

HBM & CS Classes Generators

There are many ways to generate HBM and CS classes:

  1. MYGeneration Templates: I do not recommend these templates because most of them are not updated to NHibernate newer versions and it’s not easy to change in its templates
    Download link: http://www.mygenerationsoftware.com
  2. Smart Code Studio: It’s a better way to generate the hbm files and CS classes, I’ve modified in its template to be more standard and simple, you can download my template from this link.
    (if you are not using Smart Code Studio, you can watch a video on how to use it from this link http://www.kontac.net/site/SmartCode/tabid/55/Default.aspx)
    Download link: http://www.kontac.net/site/SmartCode/Download/tabid/64/Default.aspx

Using NHibernate in Your Sharepoint Project

Create a new class library project in your solution called ABC.Domain and generate the hbm files and cs classes, then place into it.

Make sure all hbm classes are compiled as Embedded resources:

Create another class library project called ABC.BL to use the Domain project and to be used by the Sharepoint project, don’t forget to add both classes to GAC using gacutil command.

Extract the Nhibernate folder and make sure to add reference to the following DLLs + Adding reference to your Domain project:

  • Remotion.Data.Linq.dll
  • NHibernate.dll
  • Nhibernate.ByteCode.Linfu.dll
  • NHibernate.ByteCode.Castle.dll
  • log4net.dll
  • LinFu.DynamicProxy.dll
  • Iesi.Collections.dll
  • Castle.DynamicProxy2.dll
  • Castle.Core.dll

Antlr3.Runtime.dll

After adding the references to your project, make sure to install them to GAC by executing the following commands on Visual Studio Command Prompt:

gacutil -i "\Remotion.Data.Linq.dll"
gacutil -i "\NHibernate.dll"
gacutil -i "\Nhibernate.ByteCode.Linfu.dll"
gacutil -i "\NHibernate.ByteCode.Castle.dll"
gacutil -i "\log4net.dll"
gacutil -i "\LinFu.DynamicProxy.dll"
gacutil -i "\Iesi.Collections.dll"
gacutil -i "\Castle.DynamicProxy2.dll"
gacutil -i "\Castle.Core.dll"
gacutil -i "\Antlr3.Runtime.dll"
gacutil -i "\ABC.Domain\Bin\Debug\ABC.Domain.dll"

Configure your Web.config & hibernate.cfg.xml.

Prepare your hibernate.cfg.xml and place it into your website bin folder (e.g. C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin)

Now all references and configurations are ready, but if you tried to deploy your solution, you will get a run time error “Could not load file or assembly 'xyz' or one of its dependencies”. Now you will just need to add qualifyAssembly tags to your web.config (e.g., C:\inetpub\wwwroot\wss\VirtualDirectories\80\ ) to allow Nhibernate to load assemblies from GAC and not to expect it in the bin folder.

To use Nhibernate inside your Sharepoint project, you can refer to this tutorial:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hazem Torab
CEO Enozom Software
Egypt Egypt
Hazem Torab, founder & CEO at Enozom Software, a fast growing software company in Alexandria. Hazem has more than 6 years of experience in management and team leading, and 10+ years of professional experience in the software development field.
 
Hazem also is a co-founder and chairman of Ayaady for Investment and Agriculture, a crowd funded company and the first Egyptian online fresh meat shop directly from the farm to the consumers.
 
Before founding Enozom, Hazem was a co-founder & CEO of IRange Software. He also worked at ITWorx and Raya Software after his graduation in 2004 from Alexandria University, Faculty of Engineering, Computer and Systems Department.
Follow on   Twitter   LinkedIn

Comments and Discussions

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 17 Nov 2013
Article Copyright 2013 by Hazem Torab
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid