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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:59:17+00:00 2026-05-14T01:59:17+00:00

I have an ASP.NET MVC application that uses Linq to SQL repositories for all

  • 0

I have an ASP.NET MVC application that uses Linq to SQL repositories for all interactions with the database.

To deal with data security, I do trimming to filter data to only those items to which the user has access. This occurs in several places:

  1. Data in list views
  2. Links in a menu bar
  3. A treeview on the left hand side containing links to content
  4. Role-based security
  5. A special security attribute, inheriting from AuthorizeAttribute, that implements content-based authorization on every controller method.

Each of these places instantiates a repository, which opens a Linq to Sql DataContext and accesses the database. So, by my count, each request for a page access opens at least six separate Linq to SQL DataContexts.

Should I be concerned about this from a performance perspective, and if so, what can be done to mitigate it?

  • 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-14T01:59:17+00:00Added an answer on May 14, 2026 at 1:59 am

    In almost all of my MVC applications I use a BaseController. Typically I will use a factory to create an instance of the DataContext in the BaseController constructor (unit tests pass in a mock factory instance, the null constructor results in a default instance of the factory being created). While not strictly necessary, I do Dispose the created DataContext in OnResultExecuted in the BaseController. Both the “default” data context and the factory are exposed as protected properties on the BaseController class so they can be used by all inheriting controllers.

    If I need some operations to take place outside the “default” DataContext, I simply use the context factory to create a new, separate instance as necessary.

    I confess that I do this mostly for convenience and code legibility. I think the data contexts themselves are lightweight enough that I don’t gain much performance. I no longer, however, have to write the using (var context = ... code in every action method.

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

Sidebar

Related Questions

I have an ASP.NET MVC application that uses LINQ2SQL as the database layer. I
I have an ASP.NET MVC application that I wrote using LINQ to communicate with
I have an ASP.NET MVC application that currently uses the WebClient class to make
I have an ASP.NET MVC (using the release candidate) application that works with a
We're developing a reporting application that uses asp.net-mvc (.net 4). We connect through DDTEK.Sybase
I have an Asp.net MVC application which uses html5 and jquery on the client
I have an ASP.Net MVC 3 application. With 2 Areas: Auth - handles all
I'm checking out Linq for NHibernate 2.1 to use in an ASP.NET MVC application
I'm currently writing a website in ASP.NET MVC, and my database (which doesn't have
I am building a multi-layered application that has an ASP.NET MVC web application. It

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.