-->
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.  [ 3 posts ] 
Author Message
 Post subject: basic question NHibernate
PostPosted: Tue Apr 17, 2007 7:02 am 
Newbie

Joined: Tue Apr 17, 2007 6:55 am
Posts: 1
Location: Timisoara, Romania
Hello
I am a really- really beginner regarding nHibernate. I have a problem, and I tried the last three days to solve it, without any result.

I have a test database with two tables: Employees:EmployeeID,EmployeeName,EmployeeAge
Children:ChildName,EmployeeID, ChildName

Now, when I load the data from Child table, instead of telling me the EmployeeID , it says n a datagridView: WindowsApplication1.Calsses.Em,ployee.

This is because, I Think, I created the structure like that in ChildrenClass:

private Employee employee;

public Employee EmployeeID
{
get { return employee; }
set { employee = value; }
}


the .hbm.xml file:
<many-to-one name="EmployeeID" class="WindowsApplication1.Classes.Employee,WindowsApplication1" column="EmployeeID"/>


and I loaded the information like this:
IList lstChildren =(IList) session.CreateCriteria(typeof(WindowsApplication1.Classes.Children)).List();
grdChildren.DataSource = lstChildren;



Please tell me what is wrong here??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 2:18 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
You need to override your ToString() method in your Employee object. Since 'EmployeeID' is actually and Employee object, the DataGrid is just firing the ToString() method on each object...which defaults to the Type name when it isn't overriden.

Hope this helps.

Mike

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject: improper datagrid implementation
PostPosted: Wed Apr 18, 2007 10:42 am 
Newbie

Joined: Wed Dec 20, 2006 12:34 pm
Posts: 13
How are you setting the datasource for your datagrid?

I use the IList returned from the Session like this.

session.CreateCriteria(GetType(Employee)).List
dataGridView1.datasource = list

Then you can either let the datagrid build the columns for you using reflection or you can specify which properties you wish to display.

Hope this helps

Wes


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