-->
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.  [ 12 posts ] 
Author Message
 Post subject: How can I use GridView sorting with NHibernate
PostPosted: Thu Aug 31, 2006 10:00 am 
Newbie

Joined: Tue May 16, 2006 11:43 am
Posts: 7
Hallo *,

I'm using NHibernate V1.2 alpha1 with Generics Support in a ASP.NET V2 Apllication.

My question is:
How can I use the sorting-features from Gridview and Objectdatasource with generic collections from NHibernate.
I want to sort the Collection when the user click on the Column-Header of the gridview.

What Collectiontyp should I use for this and how can I resort the Collections.

An example would be great!

Thank you

Andi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 7:15 pm 
Newbie

Joined: Mon Aug 28, 2006 12:47 am
Posts: 6
Location: British Columbia, Canada
What currently happens when you do click the column header?


Top
 Profile  
 
 Post subject: Object Data Source sorting
PostPosted: Fri Sep 01, 2006 1:42 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
The built-in sorting capabilities on the DataSource controls don't work on the ObjectDataSource control since they are binding to custom objects. They work on the SqlDataSource controls.

You could spend alot of time extending the new .Net ObjectDataSource, SqlDataSource and so on but really it no simpler than writing simple IComparer implementations to do your own sorting on the collections your controls are binding to.

The new .NET 2.0 controls like the ObjectDataSource and so on aren't very useful for NHibernate development and really won't save alot of time.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 5:39 am 
Newbie

Joined: Tue May 16, 2006 11:43 am
Posts: 7
Thats wrong. The Objcetdatasource of ASP.NET V2 support sorting. It work with DataSets without coding. If you use businuess objects you have to configure the sorting. The columns of the objectdatasource have a property update-command.
My problem is how to get a collection from Hibernate that ist sortable by the columnname (property name of the business-class).

I want to have a update-command like this:
public static IList<Customer> customerUpdate (customer p, string sortExpressen)

the returned Collection should be sorted!

What generic Collectiontyp and what collection mapping should i use?

Andi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 1:25 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Maybe I misunderstood...the ObjectDataSource doesn't support sorting in the same way that the SqlDataSource control. To get sorting to work on an ObjectDataSource control you'd need to implement the sorting on the collection yourself.
My point was simply that you'd need to sort the collection that is being bound to the ObjectDataSource with code...not the "codeless" thing .net 2.0 RAD developers try to do.
I guess i just dont see the value in these DataSource controls if you are using something like NHibernate and can bind your controls to your Domain Entities directly without the overhead the DataSource controls employ by turning everything into a bloated DataSet.

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 1:44 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
mnichols wrote:
Maybe I misunderstood...the ObjectDataSource doesn't support sorting in the same way that the SqlDataSource control. To get sorting to work on an ObjectDataSource control you'd need to implement the sorting on the collection yourself.
My point was simply that you'd need to sort the collection that is being bound to the ObjectDataSource with code...not the "codeless" thing .net 2.0 RAD developers try to do.
I guess i just dont see the value in these DataSource controls if you are using something like NHibernate and can bind your controls to your Domain Entities directly without the overhead the DataSource controls employ by turning everything into a bloated DataSet.


mnichols, could you send to us some examples about using this collections? I always use datasource (ObjectDataSource) and would like to know a different way to bind data to the controls.

I think using collections it's possible to bind web controls and win forms controls, right?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 1:50 am 
Beginner
Beginner

Joined: Mon Apr 24, 2006 1:43 pm
Posts: 22
mnichols wrote:
I guess i just dont see the value in these DataSource controls if you are using something like NHibernate and can bind your controls to your Domain Entities directly without the overhead the DataSource controls employ by turning everything into a bloated DataSet.

Hmm, I'm using ObjectDataSource with NHibernate and I don't use DataSets. It was never (and still isn't) necessary to use DataSets for databinding. Just return the IList, or IList<Whatever> and bind to it.
Also, ObjectDatasource gives you an opportunity to have server side paging, and it works very well with MS Sql Server 2005 and 2005Dialect.
So, no... it's not necessary to have a code bloat with ObjectDataSource, and it usually makes a life better.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 4:08 am 
Newbie

Joined: Tue May 16, 2006 11:43 am
Posts: 7
Hi FritFrut,

how do you implement the sorting functionality of the Gridview with collections of type IList<>. I'm new in programming an object orientated business logic.
I only thing I found is to copy all Object of the collection in a List<> of the System.Collection.Generic Namespace witch implements the sort() Methode with a Comarpor.

Is this the way to go?

Andi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 6:29 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
To achieve this, we created our own collection base class that implements IList, IBindingList, IBindingListView and IComparer. Yeah, it was a fair amount of work to create an all-purpose collection class that implements these interfaces, but it was possible (so why isn't there one in the .NET 2.0 framework?)

BTW, we also created our own data source similar to ObjectDataSource (it inherits from DataSourceControl), that was also a fair amount of work, but it lets us do RAD by just specifying the HQL query. All the other crap that you normally have to do with ObjectDataSource -- specify the Select, Update, Insert and Delete methods or event handlers for them -- goes away. The designer for our data source also generates a "query result row" class that is specific to the query and exposes a property for each value selected in the query, to make binding easy.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 3:52 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
bindaandi wrote:
Hi FritFrut,

how do you implement the sorting functionality of the Gridview with collections of type IList<>. I'm new in programming an object orientated business logic.
I only thing I found is to copy all Object of the collection in a List<> of the System.Collection.Generic Namespace witch implements the sort() Methode with a Comarpor.

Is this the way to go?

Andi


ObjectDataSource doesn't do its own sorting and paging, really. It expects you to provide methods with a certain signature (currentIndex, pageSize, maxItems, sortValue, things like that). The built-in strongly-typed DataSet functionality in .NET makes it clickity-click easy to generate methods that have such signatures -- but it's buggy and I much prefer the DataLayer style that NHibernate gives us.

However, to use make the best use of sorting, paging, and such in ObjectDataSource, the easiest way is to make a thin wrapper around NHibernate. Mark your wrapper class with the DataObjectAttribute. Mark your Get methods with DataObjectMethod(DataObjectMethodType.Select) (your Saves with DataObjectMethodType.Insert, etc.).

Finally, make sure your Get() methods have the necessary parameters for sorting and paging. (string sortColumns, int startRecord, int maxRecords). You can implement paging and sorting however you want in that method, but doing it server-side with HQL is probably the most efficient.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 10:23 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 1:43 pm
Posts: 22
bindaandi wrote:
Hi FritFrut,


Sorry, I didn't reply before, I've been away.

I can't add anything to previous posts, except that, for the current project, I prefer to use Criteria instead of HQL, because I have a large number of parameters for searching, and most of them may or may not be present. Something like this:

Code:
public static IList DoSearch<ObjectType>(SearchDef s, int maxRows, int startRow, string[] asc, string[] desc) where ObjectType: OBase
{
   ICriteria cr = session.CreateCriteria(typeof(ObjectType));
   if (s != null) s.UpdateCriteria(cr);
   cr.SetFirstResult(startRow);
   cr.SetMaxResults(maxRows);

   for(int i=0; i<asc.Length; i++)
      if (!String.IsNullOrEmpty(asc[i]))
         cr.AddOrder(Order.Asc(asc[i]));

   for (int i=0; i<desc.Length; i++)
      if (!String.IsNullOrEmpty(asc[i]))
         cr.AddOrder(Order.Desc(desc[i]));      

   return cr.List() ;
}


HTH, Tom


Top
 Profile  
 
 Post subject: BindingListView Helper
PostPosted: Sat Sep 16, 2006 10:49 pm 
Newbie

Joined: Sat Apr 15, 2006 6:07 am
Posts: 4
This may be useful for you... http://sourceforge.net/projects/blw


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