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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:02:04+00:00 2026-05-26T11:02:04+00:00

The system has several classes of model (eg, tasks, invoices, reports). For each table,

  • 0

The system has several classes of model (eg, tasks, invoices, reports). For each table, depending on the logged company by some parameter(eg. companyID). And I must for every table, every query, every saving, etc. watch this parameter. Is there a simpler way to tell EF to LINQ to each query add this parameter? In other words, if I enter just:

List<Report> list = db.Reports;

that were selected only relevant records with companyID of logged company like

List<Report> list = db.Reports.Where(r => r.companyID = idOfLoggedComp)

Thanks a lot for answer.

  • 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-26T11:02:04+00:00Added an answer on May 26, 2026 at 11:02 am

    Simple answer is no. EF is completely missing global filters. You must make some wrapper class and hide the query inside custom exposed IQueryable like:

    public class CompanyRestrictedDataAccess
    {
        private int _companyId;
        private ObjectContext _context;
    
        public CompanyDataAccess(int companyId, ObjectContext context)
        {
            _companyId = companyId;
            _context = context;
        }
    
        public IQueryable<Reports> Reports
        {
            get
            {
                return _context.Reports.Where(r => r.CompanyId == _companyId); 
            }
        }
    }
    

    But this is still very poor workaround because:

    • You must use this class for queries instead of context
    • It works only for direct access. Eager loading and lazy loading completely ignores any conditions (eager and lazy loading in EF even cannot be filtered).

    So you must correctly handle your loading in the application.

    The only solution which EF provides is called Conditional mapping but it is hardcoded single filtering condition directly in EDMX so your application would work only for single company.

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

Sidebar

Related Questions

There are several types of objects in a system, and each has it's own
Say a project contains several classes, each of which has a static initializer block.
My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls
I'm using the System.DirectoryServices.AccountManagement namespace classes to manage the membership of several groups. These
I have needed in several occasions some classes to represent and manipulate conditions (typically
I have a system in production that has several servers in several roles. I
I have a page that has several ListBox es that have some cascading filtering
The web-application is a custom-built CMS which has several sub-applications and each one of
The new system I'm starting has several domains that are just join tables for
I have a (C++) system that has many classes that have variable storage (memory)

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.