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 8010531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:45:47+00:00 2026-06-04T18:45:47+00:00

I have been trying to refactor a LINQ expression into a method, and have

  • 0

I have been trying to refactor a LINQ expression into a method, and have been running into both the “Internal .NET Framework Data Provider error 1025.” and “The parameter 'xyz' was not bound in the specified LINQ to Entities query expression.” exceptions.

Here are the relevant parts of the entity model (using EF 4.2 / LINQ to Entities):

public class Place : Entity
{
    public string OfficialName { get; protected internal set; }
    public virtual ICollection<PlaceName> { get; protected internal set; }
}

public class PlaceName : Entity
{
    public string Text { get; protected internal set; }
    public string AsciiEquivalent { get; protected internal set; }
    public virtual Language TranslationTo { get; protected internal set; }
}

public class Language : Entity
{
    public string TwoLetterIsoCode { get; protected internal set; }
}

The basic relational model is this:

Place (1) <-----> (0..*) PlaceName (0..*) <-----> (0..1) Language

I am trying to create a query which will, when given a search term, try to find Place entities whose OfficialName starts with the term OR who has a PlaceName whose Text or AsciiEquivalent starts with the search term. (Language isn’t where I’m having trouble, though it is part of the query, because PlaceNames should only match for the CultureInfo.CurrentUICulture.TwoLetterIsoLanguageName.)

The following code does work:

internal static IQueryable<Place> WithName(this IQueryable<Place> queryable, 
    string term)
{
    var matchesName = OfficialNameMatches(term)
        .Or(NonOfficialNameMatches(term));
    return queryable.AsExpandable().Where(matchesName);
}

private static Expression<Func<Place, bool>> OfficialNameMatches(string term)
{
    return place => place.OfficialName.StartsWith(term);
}

private static Expression<Func<Place, bool>> NonOfficialNameMatches(string term)
{
    var currentLanguage = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    return place => place.Names.Any(
        name =>
        name.TranslationToLanguage != null
        &&
        name.TranslationToLanguage.TwoLetterIsoCode == currentLanguage
        &&
        (
            name.Text.StartsWith(term)
            ||
            (
                name.AsciiEquivalent != null
                &&
                name.AsciiEquivalent.StartsWith(term)
            )
        )
    );
}

What I am trying to do next is refactor the NonOfficialNameMatches method to extract the name => ... expression out into a separate method, so that it can be reused by other queries. Here is one example I have tried, which does not work and throws the exception “The parameter 'place' was not bound in the specified LINQ to Entities query expression.“:

private static Expression<Func<Place, bool>> NonOfficialNameMatches(string term)
{
    return place => place.Names.AsQueryable().AsExpandable()
        .Any(PlaceNameMatches(term));
}

public static Expression<Func<PlaceName, bool>> PlaceNameMatches(string term)
{
    var currentLanguage = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    return name =>
            name.TranslationToLanguage != null
            &&
            name.TranslationToLanguage.TwoLetterIsoCode == currentLanguage
            &&
            (
                name.Text.StartsWith(term)
                ||
                (
                    name.AsciiEquivalent != null
                    &&
                    name.AsciiEquivalent.StartsWith(term)
                )
            );
}

When I don’t have the .AsExpandable() chain in NonOfficialNameMatches, then I get the “Internal .NET Framework Data Provider error 1025.” exception.

I have followed other advice here such as several combinations of invoking .Expand() on the predicates, but always end up with one of the aforementioned exceptions.

Is it even possible to factor out this expression into a separate method using LINQ to Entities with LinqKit / PredicateBuilder? If so, how? What am I doing wrong?

  • 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-06-04T18:45:48+00:00Added an answer on June 4, 2026 at 6:45 pm

    The method below should work:

    private static Expression<Func<Place, bool>> NonOfficialNameMatches(string term)
    {
        Expression<Func<PlaceName, bool>> placeNameExpr = PlaceNameMatches(term);
        Expression<Func<Place, bool>> placeExpr =
            place => place.Names.Any(name => placeNameExpr.Invoke(name));
        return placeExpr.Expand();
    }
    

    EDIT: Adding additional explanations

    The PlaceNameMatches method works as you wrote it. Your issues were in how you used the method. If you want to factor out parts of an expression follow the 3 steps I did in the method above.

    1. Set a local variable to the expression created by a method.

    2. Set another local variable to a new expression that Invokes the local variable expression.

    3. Call the LinkKit Expand method: this will expand any Invoked expressions

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

Sidebar

Related Questions

I have been trying to get a jquery ajax function to return data from
have been trying to look around the web for a good wcf publish/subscribe framework
I have been trying desperately to draw some images into a view. The view
I have a linq expression that I've been playing with in LINQPad and I
Have have been trying to make a validator for my xml files. I have
I have been trying to customize a navigation bar in an iPhone app. I
I have been trying to figure out how to get a list of all
I have been trying this for a little while nut just cannot get to
I have been trying to make a simple Spring project using Eclipse and Maven
I have been trying for half a day to loop this countdown function. I

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.