none
Query problem on an EntitySet (how can I translate this) RRS feed

  • Question

  • Is there a way to translate this:

    Code:
      var result = (from s in contacts
                              from a in s.Addresses
                             where a.IdCountry.Equals(214)
                             where s.Name.Equals("Van Autreve")
                             select  s).Distinct();

    (s.Addresses is an EntitySet<Address>)

    To a simpel contacts.Where() statement?

    I just want to filter all contacts with an address in country 214.

    Thank you!
    Wednesday, September 2, 2009 11:34 AM

Answers

  • I'd do it like this:


       from c in Contacts
       where c.Addresses.Any (a => a.IdCountry == 214) && s.Name == "Van Autreve"
       select c;



    Joe


    Write LINQ queries interactively - www.linqpad.net
    • Proposed as answer by KristoferAEditor Wednesday, September 2, 2009 3:48 PM
    • Marked as answer by Yichun_Feng Friday, September 4, 2009 3:34 AM
    Wednesday, September 2, 2009 2:38 PM
    Answerer

All replies

  • I'd do it like this:


       from c in Contacts
       where c.Addresses.Any (a => a.IdCountry == 214) && s.Name == "Van Autreve"
       select c;



    Joe


    Write LINQ queries interactively - www.linqpad.net
    • Proposed as answer by KristoferAEditor Wednesday, September 2, 2009 3:48 PM
    • Marked as answer by Yichun_Feng Friday, September 4, 2009 3:34 AM
    Wednesday, September 2, 2009 2:38 PM
    Answerer
  • Thank you that works!
    Thursday, September 3, 2009 8:35 AM