views:

150

answers:

3

Dear All,

I'm new in Hibernate word, I got some source code example about Nhibernate with C# code, It worked fine, But when I try to create a new console as their example, I got many error, and I can't solve.

So I hope everybody in stacoverflow help me solve my issue.

When I try to run my C# console

hxxp://www.vi-vn.com/pubs/Forum.Image/ConfigurationNhibernate.png

hxxp://www.vi-vn.com/pubs/Forum.Image/ByteCodeProvider.png

hxxp://www.vi-vn.com/pubs/Generate Code/CS.rar

Thanks & Regards,

A: 

When I post in stackoverflow, stackoverflow says "a new user cannot post image and live link"

Sorry for this inconvenience

Regards,

QuachNguyen
+1  A: 

Here's what I do to make NHibernate work:

1.Create my model(classes+NHubenate maps) .Since I want to load my mapping files using LoadAssembly method I embed mapping files to my assembly.

2.Create a NHibernate Configuration object and I put hibernate.cfg.xml in my project bin directory to configure NHibernate:

var cfg=new Configuration();
cfg.Configure();//needs hibernate.cfg.xml to Configure.
cfg.AddAssembly(Assembly.LoadFrom("My Assembly Path"));

(You can use App.config to do all these steps)

3.I have a static ISessionFactory that will be created once (since its creation is very expensive)

sessionFactory=cfg.BuildSessionFactory();

4.From now on, every time I want to use NHibernate I'll get a session using my singleton session factory.

using(var session=sessionFactory.GetSesion())
{

}

If you are using AddAssembly method (like here) please be sure to embed your mapping files in your assembly.

Beatles1692
A: 

QuachNguyen,

I think watching the following (free) screencasts on NHibernate may be very helpful for you:

http://www.summerofnhibernate.com/

After watching this you will be able to make more sense of the errors you are getting. I'm afraid asking the stackoverflow community to help solve 'many errors' will not get you very far. No offense mate, hope this will help you.

martijn_himself