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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:29:25+00:00 2026-05-30T20:29:25+00:00

We are looking for a way of automatically filtering all CRUD operations by a

  • 0

We are looking for a way of automatically filtering all CRUD operations by a tenant ID in Entity Framework.

The ideas we thought of were:

  • Using table valued user defined functions
  • Using stored procedures (but we don’t really want to, as we’re using an ORM to avoid doing so)
  • Some how modifying the templates used to generate the SQL to add a where clause on each statement.
  • Some how modifying the templates used to generate the LINQ in the controllers (we may use MVC).

Any tips?

-thanks
Alex.

  • 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-30T20:29:26+00:00Added an answer on May 30, 2026 at 8:29 pm

    Using table valued user defined functions

    Table valued function are only available in .NET 4.5 Beta (and not available in code first). Using them will still not help you because you will have to use the function in every LINQ query so it is the same as using where clause.

    Using stored procedures (but we don’t really want to, as we’re using an ORM to avoid doing so)

    It can be useful for some special complex queries but generally it is not what you want.

    Some how modifying the templates used to generate the SQL to add a where clause on each statement.

    Too complex and on completely different level of abstraction.

    Some how modifying the templates used to generate the LINQ in the controllers (we may use MVC).

    Close to ideal solution. You simply need to wrap access to your entity set into some code which will look like:

    public class MultiTenantAccess<T> where T : IMultitenant
    {
        private IDbSet<T> set;  
    
        ... 
    
        public IQueryable<T> GetQuery(int tenantID) 
        {
            return set.Where(e => e.TenantID == tenantID); 
        }
    }
    

    Sometimes this is core for something called Generic repository but it is really just a wrapper around EF set. You will always use GetQuery to query your data store instead of using DbSet directly.

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

Sidebar

Related Questions

I'm looking for a good way to automatically 'svn add' all unversioned files in
I'm looking for a way to automatically do some clean up tasks when the
I'm looking for a way to add an EventListener which will automatically removes itself
I am using codeigniter and looking a way to enable directly editting of doc
I'm looking for a way to automatically have my RESTful controller, which returns a
I am looking for a way to automatically localize texts on buttons/textfields etc and
I'm looking for a way to automatically set the initial focus on a Silverlight
I'm looking for a way to automatically determine the natural language used by a
I'm looking for a way to automatically produce an abstract, basically the first few
I am looking for a way to automatically extract parts from audio files. Something

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.