Hi,
This is my first project using NHIbernate and I'm strugling with config issues. This is a bit long, please take a look.
This is my solution structure:
GUI - winform project
ApplicationServer.dll
DatabaseServer.dll
DataEntities.dll
The hbm files are stored in a directory in the DatabaseServer.dll (Database\Mappings)
The domain classes are in the DataEntities.dll
For now I only included only one hbm file. Its build action is set to 'Embedded Resource':
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
assembly="DataEntities"
namespace="Themis.DataEntities"
xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Project" table="PROJECTS">
<id name="PK" column="PK" access="nosetter.camelcase">
<generator class="native"/>
</id>
<property name="Name" column="NAME"/>
<property name="Id" column="ID"/>
<property name="Description" column="DESCRIPTION"/>
</class>
</hibernate-mapping>
The application will use sdf files that the user can switch so all the configuration is done through code. This code is included in DatabaseServer.dll:
Code:
Configuration cfg = new Configuration();
cfg.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
cfg.Properties["dialect"] = "NHibernate.Dialect.MsSqlCeDialect";
cfg.Properties["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlServerCeDriver";
cfg.Properties["hibernate.connection.connection_string"] = path;
cfg.AddAssembly(this.GetType().Assembly);
cfg.AddXmlFile("Mappings\\Project.hbm.xml"); ->> ERROR HERE
sessionFactory = cfg.BuildSessionFactory();
An error is thrown when the code is adding the hbm file:
NHibernate.MappingException: Could not configure datastore from file Mappings\Project.hbm.xml ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Documents\my documents\Visual Studio 2010\Projects\Application\GUI\bin\Debug\Mappings\Project.hbm.xml'.
Looking in the debug folder under the GUI project, I can see that there is no Mapping folder in it. Why is NHIbernate looking for it. Its supposed to be embedded in the DatabaseServer.dll.
Thanks,
Yoav