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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:45:44+00:00 2026-06-15T05:45:44+00:00

I’m using EF4 Code First in my Azure MVC app to retrieve data from

  • 0

I’m using EF4 Code First in my Azure MVC app to retrieve data from an SQL Azure database.

The app will have approx 200 users in total divided over a dozen organisations all using the same app. The SQL Azure DB will be storing mainly Client contact info etc.

All the tables in the SQL Azure Database include a field called OrgansiationId which is a GUID that is unique to each organisation. All data saved includes the OrganisationId corresponding to the organisation of the person saving the data.

It’s important that users only can add/edit/view information from their own Organisation.

So my question is, what is the recommended way of using LINQ to ensure that any Select statements only return information for the Users OrganisationId, without having to manually append “WHERE OrganisationId == organisationId” to every Select statement, which is vulnerable to human error. (ie Forgetting to include it so that the Organsation is not filtered, nightmare scenario!)

Is there an accepted way of acheiving this, possibly by wrapping a LINQ Statement with an additional WHERE statement so this is done automatically to all LINQ Select statements?

  • 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-15T05:45:45+00:00Added an answer on June 15, 2026 at 5:45 am

    I have implemented a very similar app. I simply wrapped the DbContext in a wrapped context:

    When this is the original context:

    public class MyContext : DbContext {
        public DbSet<MyTable> MyTable { get; set; }
    }
    

    Then the wrapped context looks like this:

    public class MyWrappedContext {
        protected MyContext InternalContext { get; set; }
        public Guid OrganizationId { get; set; }
    
        public IQueryable<MyTable> MyTable 
        {
            get 
            { 
                return InternalContext.MyTable
                   .Where(t => t.OrganizationId == OrganizationId); 
            } 
        }
    }
    

    For adding, removing and updating entities i have the following methods on the WrappedContext:

    public void Add<T>(T entity) where T : class
    {
        DbEntityEntry<T> dbEntityEntry = InternalContext.Entry(entity);
        dbEntityEntry.State = EntityState.Added;
    }
    
    public void Remove<T>(T entity) where T : class
    {
        DbEntityEntry<T> dbEntityEntry = InternalContext.Entry(entity);
        dbEntityEntry.State = EntityState.Deleted;
    }
    
    public void Update<T>(T entity) where T : class
    {
        DbEntityEntry<T> dbEntityEntry = InternalContext.Entry(entity);
        dbEntityEntry.State = EntityState.Modified;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a reasonable size flat file database of text documents mostly saved in

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.