Click here to Skip to main content
14,740,051 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 10:35am

1 solution

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

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

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