SortExpression using Operator Overload

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 18-Jan-2006 04:13:39   

I can create a relation predicate bucket using an operator overload, e.g.


            IRelationPredicateBucket filter = new RelationPredicateBucket(PersonFields.Ssn == ssn);

can I do something similar with a sort expression? if not, is this in the works for a later release?

my current code:


        public EntityCollection PhoneNumberTypes()
        {
            EntityCollection col = new EntityCollection(new PhoneNumberTypeEntityFactory());
            
            ISortExpression sort = new SortExpression(DefaultSort());

            return FetchCollection(col, null, 0, null, 0, 0);
        }

        public static ISortClause DefaultSort()
        {
            return SortClauseFactory.Create(PhoneNumberTypeFieldIndex.PhoneTypeDescr,SortOperator.Ascending);
        } 

it would be nice to use something like this...


        public EntityCollection PhoneNumberTypes()
        {
            EntityCollection col = new EntityCollection(new PhoneNumberTypeEntityFactory());
            
            ISortExpression sort = new SortExpression(++PhoneNumberTypeFields.PhoneTypeDescr);  // sorts ascending

            // ISortExpression sort = new SortExpression(--PhoneNumberTypeFields.PhoneTypeDescr);  // sorts ascending

            return FetchCollection(col, null, 0, null, 0, 0);
        }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2006 06:50:22   

What's the need for it ?!

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 18-Jan-2006 07:13:14   

Less Code?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2006 07:17:48   

SortOperator is an Enum, you may have it as follows if you would like ISortExpression sort = new SortExpression(PhoneNumberTypeFields.PhoneTypeDescr,1);

which gives the same number of keyboard hits simple_smile

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 18-Jan-2006 07:33:17   

So are you saying that the call to SortClauseFactory.Create(_ fieldIndex, _ SortOperator) isnt required?

I was under the impression that creating a sort expression required this code:

ISortExpression sort = new SortExpression(SortClauseFactory.Create(fieldIndex, SortOperatorEnum));

Which is substantially different from my pseudo code .... ISortExpression sort = new SortExpression(++PhoneNumberTypeFields.PhoneTypeDescr);

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2006 08:06:04   

Sorry I'm the one who did not understand you well.

I see your point now simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Jan-2006 09:00:01   

THis can't be done unfortunately.

'++' isn't an operator which can be overloaded. '+' is but that's overloaded for expression construction with '+' which is much more cumbersome to write otherwise.

There's an operator overloaded: SortExpression sort = new SortExpression(PhoneNumberTypeFields.PhoneTypeDescr | SortOperator.Ascending); // sorts ascending

changing: SortExpression sort = new SortExpression(PhoneNumberTypeFields.PhoneTypeDescr | SortOperator.Ascending) & (PhoneNumberTypeFields.PhoneNumber | SortOperator.Descending);

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 18-Jan-2006 13:16:44   

Cool, thanks for the help. simple_smile