This is a migrated thread and some comments may be shown as answers.

Returning a single child entity in a linq query?

0 Answers 35 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 05 Oct 2010, 11:29 AM

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

 

 

 

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
madladuk
Top achievements
Rank 2
Share this question
or