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: Get Field's Name from property.
PostPosted: Wed Jun 11, 2008 2:14 am 
Newbie

Joined: Fri Jun 06, 2008 5:27 am
Posts: 3
Hi all,

basically in my nhibernate project, i have few Objects and mapped with MS SQL.

Example :

[Class(Table = "A", Lazy = false)]
ObjectA

[Property(Name = "ADate", Column = "AD", TypeType = typeof(DateTime))]
public DateTime ADate
{
get { return _ADate; }
set { _ADate= value; }
}

Currently i'm using Nhiberhate ExecuteQuery to get the result from table. however i want to know, is there any "built-in" method to retrieve field name in MS SQL from property?
something like these -->

XXXmethod( pass in ObjectA.ADate) and these method will return the field name. In this case would be --> AD.

Kindly advice. Thanks a lot .

_________________
juz a developer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 4:47 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Hi,
you can get the column names from a property with this code:

Code:
(AbstractEntityPersister)YourSessionFactory.GetClassMetadata(type).GetColumnNames(propName)

type = your class type
propName = name of the property

you'll get a string array from this call, because nhibernate can have multiple columns mapped per property. so you have to take the first element of this array if your properties are mapped to single columns...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 10:48 pm 
Newbie

Joined: Fri Jun 06, 2008 5:27 am
Posts: 3
typhos wrote:
Hi,
you can get the column names from a property with this code:

Code:
(AbstractEntityPersister)YourSessionFactory.GetClassMetadata(type).GetColumnNames(propName)

type = your class type
propName = name of the property

you'll get a string array from this call, because nhibernate can have multiple columns mapped per property. so you have to take the first element of this array if your properties are mapped to single columns...


hi,

thanks for reply, anyway, i'm using nhibernate version 1.2.0 beta 3, and unfortunate, it don't have the GetColumnNames method... kindly advice..

_________________
juz a developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 2:27 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Oh, OK. This method only exists in NHibernate 1.2. In NHibernate 2 this method was renamed to GetPropertyColumnNames(string propName).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 10:36 pm 
Newbie

Joined: Fri Jun 06, 2008 5:27 am
Posts: 3
typhos wrote:
Oh, OK. This method only exists in NHibernate 1.2. In NHibernate 2 this method was renamed to GetPropertyColumnNames(string propName).


definately u r right! thanks a lot for the help. nice day

_________________
juz a developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 1:18 pm 
Newbie

Joined: Fri Nov 16, 2007 10:45 am
Posts: 7
typhos wrote:
Hi,
you can get the column names from a property with this code:

Code:
(AbstractEntityPersister)YourSessionFactory.GetClassMetadata(type).GetColumnNames(propName)

type = your class type
propName = name of the property

you'll get a string array from this call, because nhibernate can have multiple columns mapped per property. so you have to take the first element of this array if your properties are mapped to single columns...


Is there anything to get the reverse? Say I have a column name and I want to get the Property name that it is mapped from.


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.