none
where clause on a sub query RRS feed

  • Question

  • I trying to convert a query from t-sql to Linq. In t-sql I have something like this:
    where fielda not in (select b from t where x=y)
    How would I translate that into linq?
    Certified Geek. Data dude.
    Monday, May 24, 2010 8:28 PM

Answers

  • Hi Garvander,

     

    To avoid we assuming too much, could you please provide us with more detailed information about your scenario?   J

     

    Just another query for your references:

    ===========================================================================

    var query = from a in As

                       where !(from t in Ts where t.x == t.y select t.b).Any(t => t == a.fielda)

                       select a;

    ===========================================================================

     

    Have a nice day, both!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, May 25, 2010 3:03 AM
    Moderator

All replies

  • var results = (from b in t
         where b.x != b.y
         select b).ToList();

    I assume fielda is the same type as b since your saying not in list<b> or t.   Additionally I am assuming x and y are columns in b.

    I probably assume to much.

    Monday, May 24, 2010 9:06 PM
  • Hi Garvander,

     

    To avoid we assuming too much, could you please provide us with more detailed information about your scenario?   J

     

    Just another query for your references:

    ===========================================================================

    var query = from a in As

                       where !(from t in Ts where t.x == t.y select t.b).Any(t => t == a.fielda)

                       select a;

    ===========================================================================

     

    Have a nice day, both!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, May 25, 2010 3:03 AM
    Moderator
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 27, 2010 1:21 AM
    Moderator