Hello

I finally found what was wrong with my code.

Before creating the instance of ISessionFactory I forgot to call the
method Configure() on the Configuration object:

This is what I had (and this didn't work):

Configuration configuration = new Configuration();
ISessionFactory sessionFactory = configuration.BuildSessionFactory();

and in web.config:
<mapping assembly="Dal" />

When having a look (with the debugger) to the configuration object,
the parameters for connecting to the database where loaded but the
mappings where not loaded.

I have changed my code to:

Configuration configuration = new Configuration();
configuration.Configure();                   // Line added
ISessionFactory sessionFactory = configuration.BuildSessionFactory();

And now it's working

I'm sorry for this basic problem. I hope this can help other people.

Thanks

On 14 jan, 17:51, zbob <[email protected]> wrote:
> Hello
>
> I have created a .Net web application that connects to MySql through
> NHibernate. For doing this I have created the following assemblies:
> - Web: the web site
> - Service: the service layer called by the web site
> - Dal: data access layer using NHibernate
> - Core: class containing the domain objects
>
> I have defined the mapping files in the Dal assembly: I consider that
> the mappings are part of the Dal and that they should not be placed in
> the same assembly than the domain objects.
>
> I configure NHibernate in the web.config file with the tag <hibernate-
> configuration>. I would like to define the assembly containing the
> mappings also in the web.config file, by doing so:
>
>   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
>     <session-factory>
>       <property name="dialect">NHibernate.Dialect.MySQLDialect</
> property>
>       <property
> name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
> property>
>       <property
> name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</
> property>
>       <property
> name="connection.connection_string">MyConnectionString</property>
>       <property
> name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFa­ctory,
> NHibernate.ByteCode.Castle</property>
>       <mapping assembly="Dal" />
>     </session-factory>
>   </hibernate-configuration>
>
> (mappings are defined in assembly Dal)
>
> When doing this, I have no error, but when I query the database I have
> no results ....
>
> If I remove the tag <mapping assembly="Dal" /> from the web.config
> file and if I do the following in my code:
> Configuration configuration = new Configuration();
> configuration.AddAssembly("Dal");
>
> Then the queries are working and I can get results from the database.
>
> Would it be possible to configure NHibernate entirely in the
> web.config file with mapping files and domain objects in different
> assemblies ? All the examples I have seen define the mapping files and
> domain objects in the same assembly (I assume that by doing so it
> would work ... I have not tried this)
>
> Thanks a lot for your help
-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to