Wiki

Case Status Kiln
Log In

Wiki

 
Procedures»Adding re-ordering to a table
  • RSS Feed

Last modified on 8/7/2013 3:03 PM by User.

Tags:

Adding re-ordering to a table

Use a DynamicTable. In the RowSetup, set the RankId to the OrderRankId from the schema you will add, which should look similar to this:

CREATE TABLE OrderRanks(
    OrderRankId int NOT NULL CONSTRAINT pkOrderRanks PRIMARY KEY,
    [Rank] int NOT NULL /*This would be unique but it can't be because the swap action would creating a key violation*/
);
GO

ALTER TABLE WhatIWantToReorder ADD OrderRankId int NULL CONSTRAINT fkLinksToOrderRanks REFERENCES OrderRanks
GO

/* Add a CURSOR here to initialize the OrderRankId of each existing WhatIWantToReorder item. Then, make OrderRankId be NOT NULL.*/

If you run the app now, you should get an error saying you need to add a DataAccess class to the Providers folder. Do this, and have it implement RankingProvider.

Finally, remember to actually have the query that fills your table order by the Rank (not the ranking ID - you'll need to JOIN somehow). And have new inserts of your entity also add a row to the OrderRanks table. When you insert your rank, use RankingMethods.InsertRank() and use the return value to set the OrderRankId on your new row.