locked
Linq RRS feed

  • Question

  • User1676034882 posted

    Actually i have filename with this format "1234-GH" ,"1208-GF" like that i want to sortby by numeric order. This query is given me accurate result but i'm unable convert to in Linq Query.

    Please Help

    SELECT [file], IIF(ISNUMERIC(SUBSTRING([file],1,(IIF((CHARINDEX('-',[file]) < 1),0, CHARINDEX('-',[file]) - 1))))=0,0,SUBSTRING([file],1,(IIF((CHARINDEX('-',[file]) < 1),0, CHARINDEX('-',[file]) - 1)))) as num
    FROM product ORDER BY num desc ;

    Thanks

    Wednesday, May 9, 2018 12:57 PM

Answers

  • User-821857111 posted

    You are better off creating a stored procedure for this and calling that via EF (if that's what you are using). Alternatively, use LINQ to obtain the data and then do the sorting on the results in C# as a separate operation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 9, 2018 3:04 PM

All replies

  • User-821857111 posted

    You are better off creating a stored procedure for this and calling that via EF (if that's what you are using). Alternatively, use LINQ to obtain the data and then do the sorting on the results in C# as a separate operation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 9, 2018 3:04 PM
  • User-309798877 posted

    I will suggest better you use this query rather than LINQ

    Thursday, May 10, 2018 7:05 AM