Hi,

I have the following entities. I would like a query to get Persons whose Name = "SomePeople" and have an address = "USA". What would be the query to obtain the above result.

Thank you,

Richard

 public class Person : Entity
    {
        [Key, Field]
        public int Id { get; private set; }

        [Field(Length = 128)]
        public string Name { get; set; }

        public EntitySet<Address> AddressList { get; private set; }

    }

    public class Address : Entity
    {

        [Key, Field]
        public int Id { get; private set; }

        [Field]
        public string Country { get; set;}

    }

asked Jan 15 '14 at 19:59

rasxte's gravatar image

rasxte
20161617


One Answer:

Hello Richard,

our entity sets implement IQueryable so you can do it in the most straightforward way:

var persons = session.Query.All<Person>()
    .Where(p => p.Name=="SomePeople" && p.AddressList.Any(a => a.Country=="USA"));

answered Jan 16 '14 at 03:36

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Hi Denis,

Thank you for the answer..

I will give it a try.

Thanks again,

Richard

(Jan 17 '14 at 00:05) rasxte rasxte's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA