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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:10+00:00 2026-05-13T18:27:10+00:00

I have a edited RESTful wizard based upon Shoulders of Giants | A RESTful

  • 0

I have a edited RESTful wizard based upon Shoulders of Giants | A RESTful Wizard Using ASP.Net MVC… Perhaps? . This wizard has a CANCEL button which, when pressed, fires the code below.

// If the user cancels, drop out altogether
if (!string.IsNullOrEmpty(CANCEL_BUTTON)) {
     Session.Remove(VACANCYWIZARD_SESSION_KEY);
     repository._entities.ObjectStateManager.GetObjectStateEntry(inProgressVacancyWizard.Vacancy).Delete();
     return this.RedirectToAction("Index", "Home");
}

Now, to be able to call SaveChanges() after the cancel button I have to manually delete the entry from the wizard from my ObjectStateManager. But when you cancel the wizard by just manually returning to the home page it stays in and a next call to _entities.SaveChanges() will throw an exception that it cannot Save the object, from the wizard progress to the database, since it is still in the object state.

Note that in between the steps of the wizard I do not save anything to the database. I keep it in session state retrieving it each step:

NewVacancy inProgressVacancyWizard = Session[VACANCYWIZARD_SESSION_KEY] as NewVacancy;

Somehow, however, the inProgressVacancyWizard.Vacancy does appear in the ObjectStateManager so I have to delete it else I will get errors about incomplete Vacancies models while the _entities.SaveChanges() is called for another object.

Is there a way to cover for this problem?

//edit
After some reading I have found out that the fundaments of my repository are not good. As found here. Currently I’m doubting to implement the option mentioned in “One ObjectContext instance per business transaction” in the same article. Would that be a wise thing? I would like to hear some more about it since it will be a major refactor.

public static Repository Instance
    {
        get
        {
            if (instance == null) {
                instance = new Repository();
            }
            return instance;
        }
    }

#region Constructor: Repository()
    /// <summary>
    /// Constructor
    /// </summary>
    private Repository()
    {
        _entities = new DBModelEntitiesNew2();

    }
  • 1 1 Answer
  • 1 View
  • 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-13T18:27:10+00:00Added an answer on May 13, 2026 at 6:27 pm

    It seems like you are using a single ObjectContext instance across multiple requests. Don’t do that. It will cause you nothing but misery. It makes your web server stateful. Dispose the ObjectContext after the response is rendered (we do it, indirectly, from Controller.Dispose), and new up a new one for the next request.

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

Sidebar

Related Questions

I am attempting to write truly RESTful web services over HTTP using ASP.NET MVC
FYI: I have edited this significantly since my first edition. This simulation has been
I have edited the code by using setOnClick pending intent, and this code works
You Have edited script according to v2 i am getting this error on using
I have edited this OS 3.2 question based on advice that it could infringe
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code inside a header (edited): template <int i> class A {};
--edited for clarity (hopefully) I have an XML file that looks something like this:
I have edited this question but at the bottom of the program I have
I have edited and simplified this question a lot. If I have this method

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.