locked
LINQ TO XML QUESTION RRS feed

  • Question

  • Hi, Iam work with LINQ TO XML in my app. My  problem  is:

    What is the operator for:

    NOT IN querys and
    IN querys

    Example SImple SQL Query:

    SELECT * FROM Tbl_TST A WHERE ID NOT IN (SELECT ID FROM TST2 WHERE ID =  A.ID)

    How to make this in LINQ TO XML, i am using contains to SELECT IN but not find any argumet to use NOT IN

    Thanks.

     
    Thursday, September 25, 2008 12:23 PM

Answers

  • I don't think LINQ has provided the built-in query operator for the "IN" and "NOT IN" semantics, but you could easily implement this feature using the Contains() extension method something like the following:

    Int32[] candicates = new Int32[] { 1, 2, 3 };
    var result = from i in Enumerable.Range(1, 5) where (Enumerable.Range(1, 3)).Contains(i) select i;
    foreach (var i in result)
    {
        Console.WriteLine(i);
    }

    The above example doesn't use XLINQ, but the underlying concept still holds true since both LINQ to object and XLINQ replies on the IEnumerable to hook up extension methods.

    Hope this clears things up a little bit.
    • Marked as answer by Marco Zhou Thursday, October 2, 2008 10:27 AM
    Tuesday, September 30, 2008 8:44 AM