How would you implement a sorted list with entity infrastructure

im currently trying to figure out how I can implement something like a sorted list that contains data that can be selected by the user.

To make it more understandable, I have a set of colors, and each color can be associated with one or more products. But I do not want to display colors sorted by name or hex code. Instead, I would give the "administrator" the opportunity to independently arrange the order of colors. I am currently using an optional position attribute for sorting, but that doesn't seem right to me.

Has anyone done something similar with entity infrastructure?

Thanks for the help!

+4
source share
2 answers

If you need constant sorting, save the priority column in the color table or in the attached table (with a color ratio of 1 and - 0.1. ColorsPriority) and use it to sort.

You can use LINQ sortby or define an IComparer that uses the Priority property.

+1
source

Well, I think you're right, you can:

public class MyColor { public string name; public string hexCode; public int sortIndex; //Call it whatever you like //Other code... } 

This way, sortIndex can be set by the administrator (re-change colors), and you can sort it.

+1
source

All Articles