Click here to Skip to main content
14,268,557 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100