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

  • Home
  • SEARCH
  • 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 525305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:39:27+00:00 2026-05-13T08:39:27+00:00

Helo, i have the following code which should filter entities. Half of the code

  • 0

Helo,

i have the following code which should filter entities. Half of the code is working by i’m trying to refactor my code to get some sort of ‘subfilters’.

Basically i have the following call to filter a Users entity collection:

var result = ctx.GetUsers().WithGroups("Administrators","Users").ToList();

WithGroups has the following definition which works:

public static IQueryable<User> WithGroups(this IQueryable<User> users, params string[] groups)
{
    if (groups != null && groups.Length > 0)
    {

        var outer = PredicateBuilder.True<User>();
        var inner = PredicateBuilder.False<Group>();
        foreach (string group in groups)
        {
            string g1 = group;
            inner = inner.Or(g => g.Name == g1);
        }
        outer = outer.And(u => u.Groups.Where(inner.Compile()).Any());
        users = users.Where(outer);               
    }
    return users;
}

I’m now trying to create a filter on the Groups entities named “WithNames” which i may call within “WithGroups” to get better code. It is defined like so, which works when called directly:

public static IQueryable<Group> WithNames(this IQueryable<Group> groups, params string[] names)
{
    if (names != null && names.Length > 0)
    {
        var outer = PredicateBuilder.True<Group>();
        var inner = PredicateBuilder.False<Group>();
        foreach (var name in names)
        {
            string _n = name;
            inner = inner.Or(g => g.Name == _n);
        }
        groups = groups.Where(outer.And(inner.Expand()));
    }
    return groups;
}

var test = ctx.GetGroups().WithNames("Administrators").ToList();

I have tried this one (and some others) which doesn’t work because Linq to Entities doesn’t know “WithNames”:

public static IQueryable<User> WithGroups(this IQueryable<User> users, params string[] groups)
{
    if (groups != null && groups.Length > 0)
    {
        var inner = PredicateBuilder.False<User>();
        inner = inner.And(u => u.Groups.AsQueryable().AsExpandable().WithNames(groups).Any());
        users = users.Where(inner.Expand());
    }
    returnh users;
}

Perhaps someone may point me to a solution. I don’t have any more ideas to find a way to get around this.

Thx

  • 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-13T08:39:27+00:00Added an answer on May 13, 2026 at 8:39 am

    If you change (or overload) your WithNames and WithGroups to return Expression<Func<Group, bool>> instead of IQueryable<Group> (and similarly for Users, then you can use both of them inside calls to Where. As you’ve discovered, L2E won’t parse (this would essentially require decompiling it) a method, but it can handle an Expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer all you have to do is supply sphinx with a… May 13, 2026 at 7:25 pm
  • Editorial Team
    Editorial Team added an answer Problem was that the database I tried to attach was… May 13, 2026 at 7:25 pm
  • Editorial Team
    Editorial Team added an answer $data = array(1, 2, 3); $select->where('user_id IN (?)', $data); May 13, 2026 at 7:25 pm

Related Questions

Helo, I am pretty new to Ruby (using 1.8.6) and need to know whether
PHP 4.4 and PHP 5.2.3 under Apache 2.2.4 on ubuntu. I am running Moodle
Helo guys, I am working wid CStringArray and i want to know how to
I am writing an application which tests email addresses, for one part of this
Helo, My question is I have one Stored Procedure in SQL Server that returns

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.