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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:59+00:00 2026-06-03T07:23:59+00:00

Using Entity Framework 4.3 in one of my data access classes I have generic

  • 0

Using Entity Framework 4.3 in one of my data access classes I have generic a function like this

    public List<Company> Query(Func<Company, bool> expression)
    {
        return MyDbContext.Instance().Company.Where(expression).ToList();
    }

I use it from the bussines layer classes as MyDAL.Query(a => a.Name.Contains(textToSearch)).

Despite ofEntity Framework return the correct results, I don’t know why it instead of generate a Sql query sentence with Where clause like “Where name like ‘%’ + textToSearch + ‘%'”, It generates a sql query sentence without a where clause query all the table rows. Obviously this is very inneficient.

By the other way if in my data access clases I write a method like this:

    public List<Company> GetLikeName(string textToSearch)
    {
        return MyDbContext.Instance().Company.Where(a => a.Contains(textToSearch)).ToList();
    }

It generates correctly a Sql with where like clause.

Why If I use my generic query to retrieve results from database especifying the expression to query from my bussiness classes it generates a Sql sentence without where clause?

Thanks

  • 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-03T07:24:00+00:00Added an answer on June 3, 2026 at 7:24 am

    You need to pass the expression parameter as an Expression<>:

    public List<Company> Query(Expression<Func<Company, bool>> expression)
    

    If you just pass a Func<>, then IEnumerable.Where is called instead of IQueryable.Where, and it runs in code, not in SQL.

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

Sidebar

Related Questions

I have a WPF Datagrid populated with data from one SQL table using Entity
I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data
I've been using Entity Framework Profiler to test my data access in an MVC
I have a project with ASP.NET MVC, using Entity Framework to get data from
What does one loose by creating POCO using T4 templates in entity framework 4.0?
I recently switched from using Linq to Sql to the Entity Framework. One of
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
I'm using Entity Framework O/R mapper from Microsoft and using entity classes (generated classes
I am using Entity Framework with my website. To improve performance, I have started
I'm currently using Entity Framework and am running into this issue: The relationship between

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.