Many people (including myself) have had difficulties getting NHibernate to work with ASP.NET 2.0. The usual problem centers around how to get NHibernate to read in the configuration files for your entites and the problem is exacerbated by ASP.NET 2.0's new dynamic compilation model. I can tell you that it is possible to make it work and here is how I did it.
In ASP.NET 1.1 you could specify that configuration files, such as hbm.xml files, could be embedded resources which meant that they would get baked into the single dll produced from building your web site. You could let NHibernate know about all your entities by simply pointing it to the single dll
Configuration cfg = new Configuration(); cfg.AddAssembly("MySite.dll");
This technique also works in 2.0 if you use the Web Application Project compilation model because it works like 1.1 and builds a single dll and allows you to embed resources into that dll. But it won't work if you use the default Web Site Project compilation model or Express. Both of the latter use a dynamic compilation model where you can just copy .cs to the web site and it automatically compiles. And, as far as I know, there is no way to embed the xml configuration files into the resultant dll.
So to make it work in 2.0 here is the most direct solution. First, put all your hbm.xml files into the same directory on the server. This could be App_Code or App_Data or whevever you keep your entity classes (which should be somewhere under App_Code) or anywhere else on the web site. I put them in App_Code\Resources. Then, configure NHibernate with the AddXmlFile method giving it each and every configuration file that you have, like this:
Configuration cfg = new Configuration(); string basePath = System.Web.HttpContext.Current.Server.MapPath(@"~/App_Code/Resources/"); cfg.AddXmlFile(basePath+"Customer.hbm.xml"); cfg.AddXmlFile(basePath+"Order.hbm.xml");
Note that you have to add a line for each configuration file, which kinda sucks when you have to add more hbm.xml files to your project.
The last trick to get this working is to fix up the hbm.xml files themselves. Had you have been building a site to one specific dll (Web Project compilation, VS2003) then all your types live in that dll and it is easy to tell the xml file where the type lives. With dynamic compilation in ASP.NET 2.0 where does your entity type live? Well, if you put your entity class anywhere under the Add_Code directory it will be compiled into the App_Code.dll. Therefore, just make sure you place your entity classes somewhere under the App_Code directory and then modify your hbm.xml files to reference your entity types in App_Code.dll. Here is what my hbm.xml file starts with.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Domain.Portfolio, App_Code" table="PortfolioHead">
...
Note that this is for NHibernate 1.0. Your mapping version may need to be something different. Use whatever is appropriate for your version of NHibernate. NHibernate and ASP.NET are now one with each other.
This topic was discussed on the NHibernate forum.