-2

I'm working on a system which stores an orderBy clause as a comma-separated string in a database.

This string can contain 0-3 elements.

Is there an elegant way to write a Linq query which would handle this, without resorting to a case statement?

Here's the gist of what I'm trying to do:

var instruments = from i in db.Instruments
                  orderby "Field1, Field2, Field3"
                  select i;
Nick
  • 3,314
  • 11
  • 34
  • 42

1 Answers1

1

As usually, I will recommend to you Dynamic LINQ

Then

using System.Linq.Dynamic;
..
var instruments = db.Instruments.OrderBy("Field1").ThenBy("Field2");

You can also create own extensions, as described HERE.

Community
  • 1
  • 1