LINQ To SQL - CASE Statements
Switch functionality can be accomplished by using " Tern ary Operator " The ternary operator takes the "if" statement and turns it into an expression. Here's an example: The syntax is <condition> ? <true value> : <false value> Now, let's add a basic case statement. This will return the text "This is poisonous!" for plants with a 0 in the edible field, and "Okay to eat" otherwise. By looking at the generated SQL using the debug visualizer, we can see that a CASE statement is in fact being generated. Now the question will come up, "what if I want to have more than just one WHEN and an ELSE". In other words, how do I add more cases. Here's the trick: By replacing the "if false" value of the ternary expression with another ternary expression we logically create the same effect as a SQL CASE statement. Unlike the switch statement, this is an expression, and can be used on the ...