linq case statement

If its just the CASE statement in LINQ your after (read your comment) then an example of this is...

Int32[] numbers = new Int32[] { 1, 2, 1, 3, 1, 5, 3, 1 };

var numberText =
(
    from n in numbers
    where n > 0
    select new
    {
        Number = n,
        Text = 
        (
            n == 1 ? "One" :
            n == 2 ? "Two" :
            n == 3 ? "Three" : "Unknown"
        )
    }
);

Here's my progress so far, not working at all yet, but is a start:

var query2 = from items in db.cdsItems
             where items.ItemTrackingCode.Equals("A") && (items.ItemQtyOnHand - items.ItemQtyCommitted) > 0
             select new  {
                           items,
                           qty =
                                 (
                                    items.ItemPromoFlag.Equals("1") ? "100000" :
                                    items.ItemCat1.Equals("1") ? "100000" :
                                    items.ItemSaleStatus.Equals("O") ? "0" :
                                    (items.ItemQtyOnHand - items.ItemQtyCommitted).ToString
                                 )
                         };

This syntax seems so awkward to me... I might just pass-thru sql.

Tags:

C#

Linq

Sql