none
LINQ to SQL how to use the sql command WHERE variable in (34,35,36,57,58) RRS feed

  • Question

  • Hello

    I need to select some values from a table in a database.

    I dont know what is the equivalent in LINQ for a command like:

    WHERE  variable  in (34,35,36,57,58)
    Monday, January 12, 2009 9:50 PM

Answers

  • You can use the LINQ 'Contains' operator.  It just like SQL 'in' just the operands are reversed.
     
    int[] values = new int[] { 34, 35, 36, 57, 58 };


    var q = from x in collection
                where values.Contains(x.value)
                select x;


    Wayward LINQ Lacky
    • Marked as answer by marck68 Tuesday, January 13, 2009 6:25 AM
    Tuesday, January 13, 2009 4:12 AM
    Moderator