Is there a way to build custom expression in SqlKata for the Select/Order clause

1.1k Views Asked by At

I wanted to pass custom expression to SqlKata

The expected output is:

SELECT DISTINCT(Column1 + ' ' + Column2) FROM Table1
ORDER BY Column1 + ' ' + Column2
1

There are 1 best solutions below

0
On

You have to use Raw expressions for cases like this one, something like

var query = db.Query("Table1")
  .SelectRaw("DISTINCT(Col1 + ' ' + Col2)")
  .OrderByRaw("Col1 + ' ' + ColB");

Of course be aware of SQL injection.

check https://sqlkata.com/docs/select#raw and https://sqlkata.com/docs/order#orderbyraw