Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to linq and I'm not sure how to convert my sql script to linq :
Here is my Sql Code:

Select
[Name] 
from <table>
order by case when[Name] =
     'Texas' then 1
    else 2
end,[Name]


What I have tried:

This is what I have tried so far:

var value = from c in <table>
                        orderby c.Name
                        select new
                        {
                            NameIndex = c.Name
                        };
Posted
Updated 9-Aug-19 9:35am

1 solution

A simple way could be to use ternary conditional operator. Something like
C#
...
orderby (c.Name == "Texas" ? 1 : 2)
...

For more details on the operator, see ?: operator - C# reference | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900