Help updating Column Value +1

Posts   
 
    
ScottCate
User
Posts: 48
Joined: 11-May-2005
# Posted on: 28-Jun-2005 20:03:18   

I'm stuck on trying to update a group of rows, with a coulmn value +1.

I'm running a sortorder, and moving a row up in the order.

sample table.

id | name | sortorder

1 | mom | 0 2 | dad | 1 3 | child1 | 2 4 | child2 | 3 5 | child3 | 4 moving child2 up the list, so it's sort is 1, i'd have to move dad, and child1 sortorder to plus 1.

The sql would be update dbo.table set sortorder = sortorder+1 where id=@id sortorder >= @newSortOrder and <@OriginalSortOrder

[Param Values] @id=4 @newSortOrder = 1 @OriginalSortOrder = 3

In LLBLGen I got this far. This is for an insert, so it only needs


IRelationPredicateBucket filter = new RelationPredicateBucket();

filter.PredicateExpression.Add(PredicateFactory.CompareValue(DirectoryFieldIndex.SortOrder, ComparisonOperator.GreaterEqual, dir.SortOrder));

filter.PredicateExpression.Add(PredicateFactory.CompareValue(DirectoryFieldIndex.SortOrder, ComparisonOperator.LesserThan, NewNodeIndex));

So I have the ability to get all the rows that I want to update, I'm just not sure how to set the +1 property.

A friend of mine said that I can update all the siblings in code, and then run an Adapter.SaveEntityCollection(), and I agree that that would work.

But it just doesn't feel right. If I have 1000 siblings, then that is going to generate alot more sql then it needs to.

Thanks for the advice

ScottCate
User
Posts: 48
Joined: 11-May-2005
# Posted on: 28-Jun-2005 20:06:42   

I understand that the above code will need massaged, if the newnodeindex is being moved up or down. It's not perfect yet, as I'm still stuck on the +1 idea.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Jun-2005 20:44:59   

Please check the example in the documentation here: Using the generated code -> Field expressions and aggregates -> Expressions in entity updates.

that example increases the salary of all employees with 10%. I think you should use a similar query, directly on the database, to increase in each row a given field with 1 simple_smile

Frans Bouma | Lead developer LLBLGen Pro
ScottCate
User
Posts: 48
Joined: 11-May-2005
# Posted on: 28-Jun-2005 21:55:32   

Thanks,

I found that example, and modified the code, and it works perfect!

erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 28-Jun-2005 23:14:12   

Scott, would you mind providing your llblgen code to accomplish this task(i.e moving items up and down a list via a sortorder property? It's something I may need in the future. Thanks.