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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:50:05+00:00 2026-06-13T23:50:05+00:00

While developing a data access solution that utilizes generic repository and unit of work

  • 0

While developing a data access solution that utilizes generic repository and unit of work pattern over entity framework 4.2. I am seeing some abnormal behavior. To make my repositories generic, I have utilized the Set method of DbContext like:

public class MyGenericRepository<T> 
{
     protected readonly IDbContext context;
     public virtual IEnumerable<T> FindBy(Func<T, bool> predicate)
     {
        return context.GetDbSet<T>().Where(predicate).First();
     }
}

where IDbContext is like:

public interface IDbContext
{
    void Commit();
    void Attach<T>(T obj) where T : class;
    void Add<T>(T obj) where T : class;
    DbSet<T> GetDbSet<T>() where T : class;
    bool Remove<T>(T item) where T : class;
}

The DbContext class implements the IDbContext as:

public partial class MyEntities : IDbContext
{

    public DbSet<T> GetDbSet<T>() where T : class
    {
        return this.Set<T>();
    }
}  

When I do repository.FindBy(c => c.CompanyId == 45), Sql Profiler shows the query to NOT contain any filter (company_id = 45). The query does a Select *.

Expecting a filter to be present, i started researching and came across this,

http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/7d6705ac-f875-4c89-960b-842be6f6e5ed
and
EF DbContext.Set<T> filtered record only

These threads confirms my thought process but the results are different. Any solutions?

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-13T23:50:07+00:00Added an answer on June 13, 2026 at 11:50 pm

    Your predicate is a Func<T, bool>, which forces the query to use the Enumerable.Where method instead of the Queryable.Where method.

    Change the predicate to Expression<Func<T, bool>> and everything should start working.

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

Sidebar

Related Questions

I'm engaged in writing a product using LinqToSql for data-access. While we're rapidly developing,
I am developing an ASP.Net C# web application that should access the database using
I'm developing a program that receives some data and after processing I want to
How should one go about setting up seed data while developing an nhibernate web
while developing an Android application that uses Rickshaw to draw some charts, I encountered
I'm developing a C-program with VS2005 and I found out that when folder access
I would like to view the data in my DB while developing with Rails
While developing an application using gwt in ecliplse crashed. Now the server is running
While developing an application this is what i did : 1.Kept 320*480 as my
While developing a firefox extension, I create a wizard window from overlay.js using: this.wizard

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.