score:1

Accepted answer

try using ternary operator for all cases in your thenby clause:

 .thenby(x => x.column3 == "x" 
      ? 1 
      : x.column3 == "y" 
          ? 2 
          : x.column3 == "z" 
                ? 3 
                : defaultorder)

score:0

it'll be kind of yucky, but...

context.tablemodel.where(x => x.id == 10)
    .orderby(x => x.column1)
    .thenby(x=> x.column3 == "x" ? 1
        : x.column3 == "y" ? 2
        : x.column3 == "z" ? 3
        : defaultorder)
    .asnotracking()
    .tolistasync();

basically just a giant nested if statement.
also, the select statement is redundant if your table only has three columns.

my suggestion is to make an enum out of all your column3 values and then orderby that instead. it'll be more efficient because enum assigns int values to each item.


More Query from same tag