Aqualelaki

Hi,

I am trying to write a linq expression that will utilize a cast function in sql.

So far i can only return 2 possible values using a conditional ternary operator ( ), but i would like

to return more than 2 conditions.

My current syntax is

var result = from e in employees

select new

{ e.Name, e.Address, Region = (e.Region == "E" "East" : "West)};

The Region values are actually consist of "E", "W", "N", and "S".

How do change the syntax to get a desired result

Thanks.



Re: LINQ Project General Cast function equivalent in LINQ to SQL

Matt Warren - MSFT

I think you mean the 'CASE' function.

C# only gives you the conditional : operator. However, with it you can something similar to what you want.

var result = from e in employees

select new

{ e.Name, e.Address, Region = (e.Region == "E" "East" :

e.Region == "W" "West :
e.Region == "N" "North" :

"South")};






Re: LINQ Project General Cast function equivalent in LINQ to SQL

Aqualelaki

That's what I mean. THanks so much.