Sort Expression

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jun-2013 10:54:52   

LLBLGEN V 4.0 LLBLGEN runtime framework VB.NET Windows

Hi,

I have declared Private Shared _sorter As ISortExpression = New SortExpression()

But I am unable to syntax _sorter.Remove(_sorter) in the code.

Not sure why not?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Jun-2013 11:13:05   
 _sorter.Remove(_sorter)

What are you trying to do with the above line of code?

The Remove method, accepts a SortClause, not a SortExpression.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jun-2013 12:28:42   

Walaa wrote:

 _sorter.Remove(_sorter)

What are you trying to do with the above line of code?

The Remove method, accepts a SortClause, not a SortExpression.

I need to remove sort expression. so wondering how to do it

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Jun-2013 23:15:50   

You need to remove a sortExpression from what? I mean, normally you use a SortExpression when fetching a collection and then you pass it to a collecton.GetMulti(....,sorter) call. If you don't want to sort the collection simply don't pass your sort expression to it.

A SortExpression is a collection of SortClause objects. Maybe you want to remove a specific sort clause from the sorter. Here are some ways to do it:

var sorter = new SortExpression();
var sortClause = new SortClause(CustomerFields.City, SortOperator.Ascending);
sorter.Add(sortClause);
Assert.AreEqual(1, sorter.Count);

sorter.Remove(sortClause);
Assert.AreEqual(0, sorter.Count);

sorter.Add(sortClause);
Assert.AreEqual(1, sorter.Count);

sorter.Clear();
Assert.AreEqual(0, sorter.Count);

sorter.Add(sortClause);
sorter.RemoveAt(0);
David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 08-Jun-2013 13:27:26   

daelmo wrote:

You need to remove a sortExpression from what? I mean, normally you use a SortExpression when fetching a collection and then you pass it to a collecton.GetMulti(....,sorter) call. If you don't want to sort the collection simply don't pass your sort expression to it.

A SortExpression is a collection of SortClause objects. Maybe you want to remove a specific sort clause from the sorter. Here are some ways to do it:

var sorter = new SortExpression();
var sortClause = new SortClause(CustomerFields.City, SortOperator.Ascending);
sorter.Add(sortClause);
Assert.AreEqual(1, sorter.Count);

sorter.Remove(sortClause);
Assert.AreEqual(0, sorter.Count);

sorter.Add(sortClause);
Assert.AreEqual(1, sorter.Count);

sorter.Clear();
Assert.AreEqual(0, sorter.Count);

sorter.Add(sortClause);
sorter.RemoveAt(0);

Well, let me explain 1. I have defined Private Shared _sorter As ISortExpression = New SortExpression() 2. Then I am using _sorter = New SortExpression(TitleFields.Description Or SortOperator.Descending)

Now before the line 2 above, I need to set _sore to nothing as using the same in multiple places in the form with asc or desc on case to case basis

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jun-2013 23:48:34   

You can set _sorter to null if you want. What you cannot do is _sorter.Remove(_sorter). Also, you could have two sort expressions (_sortAsc and _sortDesc) and apply them depending on the case.

David Elizondo | LLBLGen Support Team