tags:

views:

45

answers:

2

in my nhibernate session helper class, I load my entities into the configuration like:

 static NHibernateHelper()
        {
            try
            {
                Configuration cfg = new Configuration();


                cfg.Configure();                 


                cfg.AddAssembly(typeof (Category).Assembly);
                cfg.AddAssembly(typeof (Product).Assembly);

                SessionFactory = cfg.Configure().BuildSessionFactory();
            }
            catch (Exception ex)
            {

            }
        }

It works fine if I only have 1 cfg.AddAssembly, but loading both Category and Product results in an error?

+2  A: 

Are they both in a same assembly (Category and Product). If they are, then you just need one AddAssembly.

epitka
+1  A: 

i think you are calling Configure twice try removing the first cfg.Configure();

this is how it should look :

static NHibernateHelper(){
try{
    Configuration cfg = new Configuration();
    cfg.AddAssembly(typeof (Category).Assembly);
    cfg.AddAssembly(typeof (Product).Assembly);                
    SessionFactory = cfg.Configure().BuildSessionFactory();
}
catch (Exception ex){
}}
Yassir
I just did cfg.AddAssembly("MyAssembly.Name"); and it worked, no need to add any type now!
mrblah