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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:21:08+00:00 2026-05-18T05:21:08+00:00

Does anyone have any idea how to limit result set of EntityFramework permanently? I’m

  • 0

Does anyone have any idea how to limit result set of EntityFramework permanently? I’m speaking about something like this Conditional Mapping. This is exactly what I want to achieve with one exception: I want to do this programmatically. That’s because condition value will be passed to EF only on context creation. Beside I don’t want this column to disappear from mapping.

I know how to achieve this with EF2.0 and reflection. I was using CreateQuery() method to generate my own ObjectQuery. CreateQuery() allows to inject my own ESQL query with additional condition e.g. WHERE TABLE.ClientID == value.

Problem with EF40 is that there is no more ObjectQuery but only ObjectSet and CreateQuery() is not used. I have no idea how to inject my own ESQL query.

The reason why I want to limit result sets is that I want to separate clients data from each other. This separation should be done automatically inside context so that programmers will not have to add condition .Where(x => x.ClientID == 5) to each individual query.

Maybe my approach is completely bad — but I don’t know any alternative.

  • 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-18T05:21:08+00:00Added an answer on May 18, 2026 at 5:21 am

    You don’t need reflection for this. You can simply use class inherited from ObjectContext or create custom implementation of UnitOfWork and Repositories which will wrap this functionality in better way (upper layer has access only to UnitOfWork and Repositories which do not expose EF context).

    Simple example of object context:

    public class CustomContext : ObjectContext
    {
      private ObjectSet<MyObject> _myObjectsSet;
      private int _clientId;
    
      public CustomContext(string connectionString, int clientId)
        : base(connectionString)
      {
        _myObjectSet = CreateObjectSet<MyObject>();
        _clientId = clientId;
      }
    
      public IQueryable<MyObject> MyObjectQuery
      {
        get
        {
          return _myObjectsSet.Where(o => o.ClientId == _clientId);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any idea on how to perform over-the-air, deployment of an iPhone
Does anyone have any idea how to retrieve deleted records data from Apex data
I have created a 3d environment full of 3D cubes, does anyone have any
I have a query with a complex concatenation in it. It's something along the
we have a horizontal cluster set up on JBoss 4.2. The session replication worked
I have added an observer on sales_order_place_before Event and want to customize grand total
Here is a link to my color theme that causes the problem https://gist.github.com/3d8cc59cbc1c7f87817f Does
I have a text file that is 310MB in size (uncompressed). When using PerlIO::gzip
I have been working on a Swing based java program for a while now,

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.