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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:15:32+00:00 2026-05-20T18:15:32+00:00

In my ASP.NET MVC application I need to implement persistence of data. I’ve choose

  • 0

In my ASP.NET MVC application I need to implement persistence of data. I’ve choose Entity Framework for its ability to create classes, database tables and queries from entity model so that I don’t have to write SQL table creation or Linq to SQL queries by hand. So simplicity is my goal.

My approach was to create model and than a custom HttpModule that gets called at the and of each request and that just called SaveChanges() on the context. That made my life very hard – entity framework kept throwing very strange exception. Sometimes it worked – no exception but sometimes it did not. First I was trying to fix the problems one by one but when I got another one I realized that my general approach is probably wrong.

So that is the general practice to implement for implementing persistence in ASP.NET MVC application ? Do I just call saveChanges after each change ? Isn’t that little inefficient ? And I don’t know how to do that with Services patter anyway (services work with entities so I’d have to pass context instance to them so that they could save changes if they make some).

Some links to study materials or tutorials are also appreciated.


Note: this question asks for programing practice. I ask those who will consider it vague to bear in mind that it is still solving my very particular problem and right technique will save me a lot of technical problems before voting to close.

  • 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-20T18:15:33+00:00Added an answer on May 20, 2026 at 6:15 pm

    You just need to make sure SaveChanges gets called before your request finishes. At the bottom of a controller action is an ideal place. My controller actions typically look like this:

    public ActionResult SomeAction(...) 
    {
        _repository.DoSomething();
        ...
        _repository.DoSomethingElse();
        ...
        _repository.SaveChanges();
        return View(...);
    }
    

    This has the added benefit that if an exception gets thrown, then SaveChanges will not get called. And you can either handle the exception in the action or in Controller.OnException.

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

Sidebar

Related Questions

I am working on an ASP.NET MVC application where I need to export data
I need to implement a regular expression in my asp.net mvc(C#) application using jquery.
I need to develop a generic jQuery-based search plugin for the ASP.NET MVC application
I'd like to implement ASP.Net MVC application which could have controllers, views and content
I need to get RoutData by given URL string in ASP.NET MVC application. I've
In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService
I created an data driven ASP.NET MVC Application locally and it works fine. Within
I am using Fluent nHibernate for my persistence layer in an ASP.NET MVC application,
I'm implementing a ASP.NET MVC 2 application and I need a grid with the
I want to Implement Logging future using log4net for my asp.net mvc application.. Can

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.