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: Nhibernate and DevExpress Grid
PostPosted: Wed Nov 21, 2007 8:21 am 
Newbie

Joined: Wed Nov 21, 2007 8:03 am
Posts: 2
Problem:-
We have three Master tables MAST_USER, MAST_ROLES, MAST_SITES and a single transaction table TRANS_USERTOSITETOROLE joining those masters as shown below ,


Consider we need to show data from these tables into a DevExpressGrid View (XtraGrid Control) with columns as below

user name Site name Role Name
Inder wj developer
Ashwin wj developer
Winjit wj PM


We get this data from Nhibernate by joining these tables;
we can get it in two ways,

1) Loading the User object in that object we automatically get the hierarchy  Usertositetorole in this object we get two objects one for Site and other for Role, if lazy is false through Hibernate.
2) Writing an custom join query in HQL and we get IList collection of Objects each object again having again array of objects with three elements (UserName, SteName and RoleName) .

The problem is in first case when we are binding with DataGrid we need to do custom binding i.e tracking row create event of grid and then binding these three columns to their respective fields like
Cell (“UserNAme”).Value = userobj.UserName;
Cell (“SiteName”).Value = userobj.UsertositeRoleCollection.Siteobj.SiteName;
Cell (“RoleName”).Value = userobj.UsertoSitetoRoleCollection.RoleObj.RoleName;

But all this operations + insert and update operations are very cumbersome to do it manually.

Is there any way to specify specific columns of childs to be displayed from collection automatically by setting some properties way so that Hibernate handles all the operations internally on objects.????

And in second case again the binding is custom (manually) but here we do not have any objects of business entities ,its list of objects so here if we are modifying any rolename we need to keep track against which user and site this role is changed this can be done by getting primary keys also but our manipulation operation will include an extra load operation .???

Please let us know which is the efficient way of achieving this operation? Are we doing something in wrong way, are we missing any perfect way of handling this???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 10:15 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
I use the BindingList support for XtraGrid. I also use a DTO (Data Access Object) but you can skip that if you like.

My grid-destined code ends up looking something like below.

So after populating AccountDtoList class, I throw it into the grid by setting the DataSource, then I just have to call 'SaveOrUpdate()' on each List item (or a specific one), if someone presses a Save button.

But, I don't really know if can answer your question as specifically as you were hoping (I think your question might be too detailed and probably nothing to do with NHibernate). But this should be enough to get you started. You should also be reading the DevExpress documentation.

Code:
public class AccountDtoList : BindingList<AccountDto> { }

public class AccountDto
{
   private string _userName;
        public string UserName
   {
      get { return _userName; }
                set { _userName = value; }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 6:01 pm 
Newbie

Joined: Tue Mar 21, 2006 3:11 pm
Posts: 10
I have a somewhat similar situation. I have a parent table and I need to know if a row exists in a child table with specific criteria. I also want to display the value of this check in a cell of a grid. In my case, the easiest solution was to add a Property based on a formula that calls a stored proc to perform the query.

Code:
<property name="HasUnverifiedStipulations" type="Boolean"
    formula="(select dbo.CreditAppHasUnverifiedStipution(CredAppId))" />


This lets me execute a query in the stored proc that pulls just the data I need without having to hit and load the lazy collection of child objects. Not having to perform this saves time and also helps the business objects stay a bit cleaner. Also, adding an "HasUnverifiedStipulations" attribute to my business object made sense, this may not be true for you however.


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.