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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:36+00:00 2026-05-24T23:15:36+00:00

I have stumbled upon a riddle which I can’t explain, maybe someone here will

  • 0

I have stumbled upon a riddle which I can’t explain, maybe someone here will be able to.
Here is a (rather lengthy but complete) code snippet:

public class Foo
{
    public int ID { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Foo> InnerFoo { get; set; }
}

public class AppContext : DbContext
{
    public IDbSet<Foo> Foos { get; set; }
}

public class Initializer : DropCreateDatabaseAlways<AppContext>
{
    protected override void Seed(AppContext context)
    {
        var list = new List<Foo>
                       {
                           new Foo {Name = "one", InnerFoo = new List<Foo>{new Foo {Name = "Four"}}},
                           new Foo {Name = "two"},
                           new Foo {Name = "three"},
                       };

        list.ForEach(f => context.Foos.Add(f));
    }
}

public class Filter
{
    public static Expression<Func<Foo, bool>> GetPredicate()
    {
        return p => p.Name != null && p.Name.Length > 3;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Database.SetInitializer(new Initializer());
        using (var ctx = new AppContext())
        {
            var predicate = Filter.GetPredicate();
            var list = ctx.Foos.Where(f => f.InnerFoo.AsQueryable().Where(predicate).Count() > 0).ToList(); // this works
            // var list = ctx.Foos.Where(f => f.InnerFoo.AsQueryable().Where(Filter.GetPredicate()).Count() > 0).ToList(); // this doesn't
            foreach (var s in list)
            {
                Console.WriteLine(s.Name);
            }
        }
    }
}

The line that’s commented out doesn’t work – throws an exception at runtime – “Internal .NET Framework Data Provider error 1025.”. I’m using EntityFramework.4.1.10715.0

Can anyone tell me why?

Side question: I’m looking for a way to keep filtering expressions that are used in several different classes.

  • 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-24T23:15:36+00:00Added an answer on May 24, 2026 at 11:15 pm

    The problem is that your inner Where is already within the context of an “outer Where” on ctx.Foos – so the call to Filter.GetPredicate() ends up as part of the expression tree, and the Entity Framework has no idea what it means or how to translate it into SQL.

    That’s why it’s happening… I’m not sure of the best solution right now though, unless you can extract the predicate into a separate variable where you need it.

    (As an aside, it’s generally more expressive to use Any(...) than ...Count() > 0 – and in LINQ to Objects it can make a huge difference.)

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

Sidebar

Related Questions

I'm mucking about with jQuery AJAX and have stumbled upon an oddity (or rather
I'm quite new to hibernate and have stumbled on this problem, which I can't
I have stumbled upon a problem when calling a nested Async which happens to
I'm hoping someone happens to have stumbled upon the following issue before. My Java
I am currently experimenting with various input controls and have stumbled upon SneakyInput, which
I have stumbled upon an issue I can't figure out right now. I get
I stumbled upon an interesting error that I've never seen before, and can't explain
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I
I'm revisiting som old code of mine and have stumbled upon a method for
I have recently stumbled upon a problem with selecting relationship details from a 1

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.