Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Dynamic sorting
 

Pages: 1
LLBLGen Pro Runtime Framework
Dynamic sorting
Page:1/1 

  Print all messages in this thread  
Poster Message
Rob
User



Location:
Gold Coast, Queensland, Australia
Joined on:
17-Sep-2004 13:51:52
Posted:
50 posts
# Posted on: 02-Nov-2004 12:43:29.  
Hi!

I find myself writing many and huge switch statements to get around issues which I hope will have a more dynamic capability (only I haven't found it out yet.)

There is a great collection in the EntityCollections called Fields. It is obviously for dynamic access to fields in the EntityClass.

Code:

private string testFunc(string sFieldName)
{
SomeTableCollection sometablecollection = new SomeTableCollection();
sometablecollection.GetMulti(null);
return sometablecollection.Fields[sFieldName].ToString();
}


This is great!

I now wonder if there is a similar appoach to the FieldIndex. I would like to be able to pass which field to sort on to a function. So far I have handled this by using Switch statements based on the sSortField argument. But that is a very cumbersome way to do it. Especially with many tables and Sort field candidates. I wonder if there is something like:

Code:

private string testFunc(string sSortField)
{
SomeTableCollection sometablecollection = new SomeTableCollection();
ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(SomeTableFieldIndex[sSortField], sortOperator.Ascending));
sometablecollection.GetMulti(null);
}


Is there some similar way to do this already?

Gratefully,

!Rob
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37321 posts
# Posted on: 02-Nov-2004 13:42:12.  
Rob wrote:
Hi!

I find myself writing many and huge switch statements to get around issues which I hope will have a more dynamic capability (only I haven't found it out yet.)

There is a great collection in the EntityCollections called Fields. It is obviously for dynamic access to fields in the EntityClass.

Code:

private string testFunc(string sFieldName)
{
SomeTableCollection sometablecollection = new SomeTableCollection();
sometablecollection.GetMulti(null);
return sometablecollection.Fields[sFieldName].ToString();
}


This is great!

Err Regular Smiley I hope I won't spoil your party, but I'm not aware of a Fields collection in a collection. The entities inside a collection however have a fields collection. So you probably meant:
return sometablecollection[index].Fields[sFieldName].ToString(); ?

Quote:

I now wonder if there is a similar appoach to the FieldIndex. I would like to be able to pass which field to sort on to a function. So far I have handled this by using Switch statements based on the sSortField argument. But that is a very cumbersome way to do it. Especially with many tables and Sort field candidates. I wonder if there is something like:
Code:

private string testFunc(string sSortField)
{
SomeTableCollection sometablecollection = new SomeTableCollection();
ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(SomeTableFieldIndex[sSortField], sortOperator.Ascending));
sometablecollection.GetMulti(null);
}


Is there some similar way to do this already?

Of course Regular Smiley

Code:

private string testFunc(SomeTableFieldIndex index)
{
SomeTableCollection sometablecollection = new SomeTableCollection();
ISortExpression sorter = new SortExpression();
sorter.Add(new SortClause(EntityFieldFactory.Create(index), sortOperator.Ascending));
sometablecollection.GetMulti(null, ..... , sorter, ....);
}


This should do it Regular Smiley


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Rob
User



Location:
Gold Coast, Queensland, Australia
Joined on:
17-Sep-2004 13:51:52
Posted:
50 posts
# Posted on: 03-Nov-2004 01:44:30.  
Hey Otis!

In regards to .Fields collection, yes of course you are right, I saw my error after I posted it.

I realise that your solution for my sorting problem would work. However it is not quite what I am after. I want to be able to pass in a string containing the name of the field to sort on, not its' LLBLGen generated index. What I am doing in this case is, I am rendering dropdownlists onto forms, and the information about what goes in the dropdownlists is stored in the database. It is sort of a Content Management System approach to building forms. This is so that my application can have configurable data entry forms.

So, can I pass in a string with the field name and use this string to control the sorting?

!R
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37321 posts
# Posted on: 03-Nov-2004 10:13:43.  
Rob wrote:
Hey Otis!

In regards to .Fields collection, yes of course you are right, I saw my error after I posted it.

I realise that your solution for my sorting problem would work. However it is not quite what I am after. I want to be able to pass in a string containing the name of the field to sort on, not its' LLBLGen generated index. What I am doing in this case is, I am rendering dropdownlists onto forms, and the information about what goes in the dropdownlists is stored in the database. It is sort of a Content Management System approach to building forms. This is so that my application can have configurable data entry forms.
So, can I pass in a string with the field name and use this string to control the sorting?
!R

If you know the type of the entity, sure Regular Smiley. do:

IEntityFields fields = EntityFieldsFactory.Create(EntityType.SomeTableEntity);
and then instead of calling EntityFieldFactory.Create(enum), you simply pass: fields["name"] to the constructor of SortClause() Regular Smiley


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Rob
User



Location:
Gold Coast, Queensland, Australia
Joined on:
17-Sep-2004 13:51:52
Posted:
50 posts
# Posted on: 04-Nov-2004 03:36:49.  
Hey Otis!

I guess you mean: Wink

Code:

IEntityFields fields = EntityFieldsFactory.CreateEntityFieldsObject(EntityType.SomeTableEntity);


Thanks for the tip, it worked like a charm. I wish there was a way I could find these things out for myself.

!Rob
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37321 posts
# Posted on: 04-Nov-2004 09:03:18.  
Rob wrote:
Hey Otis!

I guess you mean: Wink

Code:

IEntityFields fields = EntityFieldsFactory.CreateEntityFieldsObject(EntityType.SomeTableEntity);


err, yes Wink I didn't look closely to the method.

Quote:

Thanks for the tip, it worked like a charm. I wish there was a way I could find these things out for myself.
!Rob

There is no other way than to look into the generated code and into the reference manual, where these classes/methods are explained. Regular Smiley


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
un.real
User



Location:
Ankara, TR
Joined on:
27-May-2005 16:21:37
Posted:
12 posts
# Posted on: 19-Jul-2005 11:24:27.  
hello guys;

I've read your discussion but couldn't solve my problem. I think my problem is the same with Rob's: sorting a typedList by a string parameter.

I want to do something like this:

Code:

private sometableTypedList GridListFiller(string sortField){
sometableTypedList Tlist = new sometableTypedList();

ISortExpression sorter = new SortExpression();
sorter.Add(sortField, SortOperator.Descending);

Tlist.Fill(0,sorter,false,null);

return Tlist;

}


I tried the piece of code above (the one Otis wrote) but it didn't work.??

please help me Regular Smiley
thanks in advance.
abdullah.

You never know if you don't go
You never shine if you don't glow
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37321 posts
# Posted on: 20-Jul-2005 11:22:30.  
what does 'didn't work' mean exactly? You got an exception, error or nothing was sorted? Could you please turn on tracing for the DQE (See 'Using the generated code / troubleshooting and debugging' in the docs) to see which query is generated exactly?

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
un.real
User



Location:
Ankara, TR
Joined on:
27-May-2005 16:21:37
Posted:
12 posts
# Posted on: 20-Jul-2005 17:59:34.  
I started a new thread for this and just saw that u replied to it. Wink

BTW, by "didn't work", I meant it didn't sort the data. probably it was me making a mistake.
You never know if you don't go
You never shine if you don't glow
 
Top
jshallard
User



Location:
Florida, USA
Joined on:
23-Mar-2005 13:22:12
Posted:
62 posts
# Posted on: 02-Jan-2007 17:41:42.  
I am using an LLBLGenProDataSource with a DataContainerType or TypedView. This binds to a datagrid.

I am trying to construct some dynamic sorting. In a post in this thread, Otis posted the following code snippit:

Quote:
ISortExpression sorter = new SortExpression();
sorter.Add(new SortClause(EntityFieldFactory.Create(index), sortOperator.Ascending));


How would you deal with the sorting in this case, as the SortClause seems to need an EntityField, but the LLBLGenProDataSource is using a TypedView?

Thanks for any help


  Top
bclubb
User



Location:
Norman, Oklahoma
Joined on:
12-Feb-2004 22:18:04
Posted:
934 posts
# Posted on: 03-Jan-2007 03:08:59.  
An overload of create will accept the typed view as the first parameter and the field name as the second to create the field.

EntityFieldFactory.Create("myTypedView", "fieldName")
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37321 posts
# Posted on: 03-Jan-2007 09:59:33.  
A typedview also uses Entityfield(2) objects Regular Smiley

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
jshallard
User



Location:
Florida, USA
Joined on:
23-Mar-2005 13:22:12
Posted:
62 posts
# Posted on: 03-Jan-2007 10:11:58.  
Thanks - that works great now Regular Smiley
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.