Returning a single child entity in a linq query?

1 posts, 0 answers
  1. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 05 Oct 2010 Link to this post

    Hi all.

    I have a one-to-many relationship for my entity set, however on some occasions I only want to return one of the child entities, however when using the include function I cannot change my where clause to single out the child entities;

    Sample query, so in this case the data_PERSON can have multiple data_ROLE entities, however I may just want to bring back one data_ROLE record [as an example their active role]

    public IQueryable<data_PERSON> GetDataForTeam(System.Guid personguid)
    {
                return this.ObjectContext.data_PERSON
                    .Include("data_ROLE");
    }

    So when I do the where clause I cannot query the data_ROLE so in essence want some like this;

     

    public IQueryable<data_PERSON> GetDataForTeam(System.Guid personguid)
    {
                return this.ObjectContext.data_PERSON
                    .Include("data_ROLE");
                    .Where(o=>o.data_ROLE.isactive==true);
    }

    Thanks

    P

     

     

     

Back to Top