Get records based on child condition

Posted by Shawn Mclean on Stack Overflow See other posts from Stack Overflow or by Shawn Mclean
Published on 2010-04-08T19:50:33Z Indexed on 2010/04/08 19:53 UTC
Read the original article Hit count: 195

Filed under:

In LINQ To Entities: How do I get the records (including both child and parent) based on a condition of the child in a one to many.

My structure is set up as follows:

  • GetResources() - returns a list of Resources.
  • GetResources().ResourceNames - this is the child, which is an entity collection.
  • GetResources().ResourceNames - a property of one record of this child is Name.

I'd like to construct something like this:

return (from p in repository.GetResources()
             where p.ResourceNames.Exist(r => r.Name.Contains(text, StringComparison.CurrentCultureIgnoreCase))
             select p).ToList();

but of course, Exist doesn't exist.

thanks.

© Stack Overflow or respective owner

Related posts about linq-to-entities