Lets say I have a table called Projects
in my SQL server.
My dbml file has the Project
object, and I use a list of Projects in multiple views of my MVC application.
The thing is: Ordering.
By default then you use linq the Projects are ordered by ID.
lets say I want them ordered by Name
and then by Code
.
_db.Projects.Ordery(q=>q.Name).ThenBy(q=>q.Code)
easy.
Now, I use this list of projects in several views, with different statements in the Where
clause.
everywhere i need to add the same .Ordery(q=>q.Name).ThenBy(q=>q.Code)
this is not DRY.
If I were to change the order to make it first by code
then by name
i need to change that in several places.
What is my question: How do I DRY up the ordering. How would I have 1 place, where I define how the ordering of a list of Projects should be done.
surely I cant be the first with this kind of question. Tips will be very welcome.