Configure nHibernate for multiple-project solution

Posted by NoOne on Stack Overflow See other posts from Stack Overflow or by NoOne
Published on 2010-03-15T22:58:46Z Indexed on 2010/03/16 13:56 UTC
Read the original article Hit count: 190

Filed under:
|

Hello,

Im doing a project with C# winforms. This project is composed by:

alt text

  • Client project: Windows Forms where user will do CRUD operations on the models;
  • Server project;
  • Common Project: This project will hold the models (in the image only have the model Item);
  • ListSingleton: Remote Object that will do the operations on the models;

I already have all the communication working, but now I need to work on the persistence of the data in a mysql database. I was trying to use nHibernate but I’m having some troubles.

My main problem is how to organize my hibernate configuration.

  • In which project do I keep the mapping? Common project?

  • In which project do I keep the hibernate configuration file (App.config)? ListSingleton project?

  • In which project do I do this:

        Configuration cfg = new Configuration();
        cfg.AddXmlFile("Item.hbm.xml");
        ISessionFactory factory = cfg.BuildSessionFactory();
        ISession session = factory.OpenSession();
        ITransaction transaction = session.BeginTransaction();
    
    
    
    Item newItem = new Item("BLAA");
    
    
    // Tell NHibernate that this object should be saved
    session.Save(newItem);
    
    
    // commit all of the changes to the DB and close the ISession
    transaction.Commit();
    session.Close();
    

In the ListSingleton project? Altho I had reference to the Common Project in the ListSingleton I keep getting error in the addXml line…

My mapping is correct because I tried with a one-project solution and it worked :X

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate