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.  [ 2 posts ] 
Author Message
 Post subject: Get "column" attribute's value from many-to-one
PostPosted: Mon Aug 27, 2007 6:46 am 
Newbie

Joined: Mon Aug 27, 2007 6:33 am
Posts: 2
Hi

I am trying to get the value of the column attribute of a many-to-one in C# code. I believe I am close, but I am not sure how to use the .GetIdentifierOrUniqueKeyPropertyName(???) method found in the ManyToOneType class.

Below is the Mapping document, and code I use to get to the above mention method.

Thanks!

Kind Regards,
Nicholas


Hibernate version:
NHibernate 1.2.0

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Generic2.Security.User, Generic2.Security" table="[User]">
<id name="ID" type="Int32">
<generator class="identity" />
</id>

<property name="UserName" type="String"/>
<property name="Password" type="String" />

<property name="RoleID" type="Int32" />
<many-to-one name="Role" class="Generic2.Security.Role, Generic2.Security" column="RoleID" unique="true"
update="false" insert="false"/>

<property name="FirstName" type="String" />
<property name="LastName" type="String" />
<property name="Enabled" type="Boolean" />
<property name="ChangePassword" type="Boolean" />
<property name="LastPasswordChange" type="DateTime" />
<property name="FailedLogins" type="Int32" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

((NHibernate.Type.ManyToOneType)sessionFactory
.GetClassMetadata(typeof(User)).GetPropertyType("Role"))
.GetIdentifierOrUniqueKeyPropertyName(???);

Name and version of the database you are using:
SQL Server 2005


Top
 Profile  
 
 Post subject: i got it
PostPosted: Mon Aug 27, 2007 7:58 am 
Newbie

Joined: Mon Aug 27, 2007 6:33 am
Posts: 2
//get class
NHibernate.Mapping.PersistentClass myClass = NHibernateHelper.GetConfiguration(NHibernateHelper.GetConfigName(typeof(User))).GetClassMapping(typeof(Generic2.Security.User));

//get column
NHibernate.Mapping.Column referenceColumn = ((NHibernate.Mapping.Column)((IList)myClass.GetProperty(sfProperty.PropertyInfo.Name).ColumnCollection)[0]);

string colName = referenceColumn.name;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.