Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 724155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:11:23+00:00 2026-05-14T06:11:23+00:00

I created a LINQ extension as talked about here . But apparently, it does

  • 0

I created a LINQ extension as talked about here. But apparently, it does not work with queries on the child. As seen in the code below:

return (from p in repository.GetResources()
                where p.ResourceNames.Any(r => r.Name.WhereIn(arg => arg.Name, "PartialWord"))
                select p).ToList();

What I want to accomplish is that ResourceNames is an EntityCollection, which I need to check if the property ‘Name’ of the children to see if they contain the word ‘PartialWord’.

WhereIn works on like this:

repository.GetResources().WhereIn({CODEHERE});

but when placed on the child, it does not work. Is there a special way to set up my extension. This is it below:

public static class QueryableExtensions
{
    private static Expression<Func<TElement, bool>> GetWhereInExpression<TElement, TValue>(Expression<Func<TElement, TValue>> propertySelector, IEnumerable<TValue> values)
    {
        ParameterExpression p = propertySelector.Parameters.Single();
        if (!values.Any())
            return e => false;

        var equals = values.Select(value => (Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue))));
        var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.Or(accumulate, equal));

        return Expression.Lambda<Func<TElement, bool>>(body, p);
    }

    /// <summary> 
    /// Return the element that the specified property's value is contained in the specifiec values 
    /// </summary> 
    /// <typeparam name="TElement">The type of the element.</typeparam> 
    /// <typeparam name="TValue">The type of the values.</typeparam> 
    /// <param name="source">The source.</param> 
    /// <param name="propertySelector">The property to be tested.</param> 
    /// <param name="values">The accepted values of the property.</param> 
    /// <returns>The accepted elements.</returns> 
    public static IQueryable<TElement> WhereIn<TElement, TValue>(this IQueryable<TElement> source, Expression<Func<TElement, TValue>> propertySelector, params TValue[] values)
    {
        return source.Where(GetWhereInExpression(propertySelector, values));
    }

    /// <summary> 
    /// Return the element that the specified property's value is contained in the specifiec values 
    /// </summary> 
    /// <typeparam name="TElement">The type of the element.</typeparam> 
    /// <typeparam name="TValue">The type of the values.</typeparam> 
    /// <param name="source">The source.</param> 
    /// <param name="propertySelector">The property to be tested.</param> 
    /// <param name="values">The accepted values of the property.</param> 
    /// <returns>The accepted elements.</returns> 
    public static IQueryable<TElement> WhereIn<TElement, TValue>(this IQueryable<TElement> source, Expression<Func<TElement, TValue>> propertySelector, IEnumerable<TValue> values)
    {
        return source.Where(GetWhereInExpression(propertySelector, values));
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:11:24+00:00Added an answer on May 14, 2026 at 6:11 am

    Presuming ResourceName.Name is a string:

    You don’t need any extension for the string version of .Contains() in L2E. (You do need it for the list version in L2E v. 1 only). You should be able to do:

    return (from p in repository.GetResources()
            where p.ResourceNames.Any(r => r.Name.Contains("PartialWord"))
            select p).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like Linq but find that once the designer has created my classes I
I'm not entirely sure the title is properly worded, but here's the situation... I
I am trying to mimick the left outer join here but using dynamic linq
Using extension syntax I'm trying to create a left-join using LINQ on two lists
My DAL is created using Linq and all is fine. However, on one page,
Simple. I created a LINQ-TO-SQL Entity model, created a website, added a Data Service
I am using LINQ to access my database, and thereby gets a LINQ-created object
I have created some extra functionality on my Linq-to-SQL classes to make things easier
I've created a DBML file for a LINQ to SQL mapping and after dragging
I have a LINQ TO SQL Context that I have created that calls a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.