Reputation: 123
im currently try to figure out how I could implement something like a sorted list which holds data that can be selected by a user.
To make it more clear, i have a set of colors and each color can be linked to one or more products. But i don't wont to display the colors sorted by name or hex code. Instead i would give the "admin" the possibility to arrange the order of the colors by himself. Currently i use an additional position attribute for sorting, but it doesn't feel right to me.
Does anybody have done something like this with the entity framework?
Thanks for help!
Upvotes: 4
Views: 1146
Reputation: 4328
Well, I think you are right, you can have:
public class MyColor
{
public string name;
public string hexCode;
public int sortIndex; //Call it whatever you like
//Other code...
}
So the sortIndex can be set by the admin (rearange the colors), and you can sort by it.
Upvotes: 1
Reputation: 18118
If you want a persistent sorting, store a priority column in Colors table or in an attached table (with Colors 1 <-- 0..1 ColorsPriority relationship) and use it for sorting.
You can either use LINQ's sortby or define an IComparer that uses the Priority property.
Upvotes: 1