These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: NHibernate and Visual Studio 2005
PostPosted: Wed Aug 09, 2006 4:54 am 
Newbie

Joined: Tue Aug 08, 2006 3:15 pm
Posts: 2
Hello,

I'm newbie in NHibernate.
I'd like to use NHibernate with Visual Studio.
I generate all my classes and the Nhibernate mapping file with a free software found in MyGenerationSoftware.
However, when trying few generated classes, Visual Studio doesn't seem to find the mapping file, wherever I put it even if I configure it to search in a specific directory...

Does anybody encounter this problem ?
Any help is welcome.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 5:56 am 
Newbie

Joined: Tue Aug 08, 2006 5:51 am
Posts: 9
Hi tpsisavath,

Try to add your mappings file to the configuration explicitly. Example:

Configuration cfg = new Configuration();
cfg.AddXmlFile("somePath\\yourMappings.hbm.xml");

Regards, Tonn


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 8:10 am 
Newbie

Joined: Mon Aug 14, 2006 7:57 am
Posts: 1
Location: Brazil
Tonn wrote:
Hi tpsisavath,

Try to add your mappings file to the configuration explicitly. Example:

Configuration cfg = new Configuration();
cfg.AddXmlFile("somePath\\yourMappings.hbm.xml");

Regards, Tonn


Tonn,

I'm trying this aproach (i'm using VS2005 too) but it's no working. In my case my class is in App_Code\Department.vb together with the App_Code\Department.hbm.xml file.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 10:51 am 
Newbie

Joined: Tue Aug 08, 2006 5:51 am
Posts: 9
Lets look into that.
(Btw I'm doing C# but the port to VB should be straightforward)


Try this (tested code) using your own filename, classname and propertyname:

Configuration cfg = new Configuration();
cfg.AddXmlFile(@"D:\C#\test\HibernateTest\HibernateTest\User.hbm.xml"); // your filename here

NHibernate.Mapping.PersistentClass pclass = cfg.GetClassMapping(typeof(User)); // your classname here instead of User
MessageBox.Show(pclass.MappedClass.Name);

NHibernate.Mapping.Property property = pclass.GetProperty("Username"); // your propertyname here instead of Username
MessageBox.Show(property.Name);


See if I you get errors like:
"Could not find file"
pclass == null
"property not found: ..."

If you don't get an error your mapping file is loaded.
Let me know...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 4:55 pm 
Newbie

Joined: Mon Apr 10, 2006 11:45 pm
Posts: 17
do you guys have the mapping files being built as an embedded resource? I'm not sure if that's associated with the problems you folks are having but I had problems figuring that out when I started. To do it just right click on the .xml file in VS and go to properties and set the build action to embedded resource.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 3:40 am 
Newbie

Joined: Tue Aug 08, 2006 5:51 am
Posts: 9
Hi w00tfest99,
Thanks for your response.


We're now talking about two basic methods:

1) Add the MyMappings.hbm.xml as an embedded resource and use MyConfiguration.AddAssembly("MyAssembly");

2) Simply use MyConfiguration.AddXmlFile("MyMappings.hbm.xml");


Method 1) is generally used in toturials but all newbies (you and me included) seem to trip over the correct settings.
Method 2) is more intuitive. You simple add the file mentioned, that's all. It doesn't have to be an embedded resource. It doesn't have to be part of your project.

So if things don't work I always suggest to try method 2).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.