cremor wrote:
I've also had this probelm and I only found two solutions:
1. Use a old style Website-Project in VS. That will give you the possibility to name the assembly.
2. Create a library for your business objects and mappings.
I've chosen solution 2 because of the drawbacks old Website-Projects have.
Thanks! This was road to success. It also matched the paradigm I typically use for solution organization. A Web UI, classLibrary BO (Business Objects/Logic) project and another classLibrary DA (Data Access) project. I tried a couple of ways to organize and found that you can put the hbm mapping files by themselves in the DA project and point at them from web.cofig setting. For the hbm content itself you need to set the assembly and namespace attributes to point to the BO project assembly and all works well.
NOTE -- as whoami suggests, one does need to set the Build Action to Embedded Resource; to do so, with the *.hbm.xml file in a class library project, right-click on the file, select Properties and in the Advanced Section find the Build Action property listed with its drop-down selector.
Tested okay with NHibernate 2.0.0-GA too.
Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.connection_string">server=localhost; database=db1; Integrated Security=SSPI;</property>
<mapping assembly="NHibernateSandBox.DA" />
</session-factory>
</hibernate-configuration>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernateSandBox.BO" namespace="NHibernateSandBox.BO" >
<class name="User" table="Users">
<!-- A 32 hex character is our surrogate key. It's automatically generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="id" sql-type="nchar(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>
<property name="Name" column="name" type="string" />
</class>
</hibernate-mapping>
Code:
namespace NHibernateSandBox.BO
{
public class User
{
private string id;
private string name;
public User()
{
// constructor
}
public virtual string Id
{
get { return id; }
set { id = value; }
}
public virtual string Name
{
get { return name; }
set { name = value; }
}
}
}
[/i]