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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:43:04+00:00 2026-05-24T23:43:04+00:00

I’m creating an Asp.Net MVC 3 application with NHibernate as my ORM. In my

  • 0

I’m creating an Asp.Net MVC 3 application with NHibernate as my ORM. In my my edit action method I call the Save method in my DatabaseAccessObject class, but instead of updating the object it creates a new one. I can’t figure out why.

Here’s the code for the method that returns my configured SessionFactory, and my global.asax.cs file where I’m storing the SessionFactory:

public static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString("Server=(local);Database=WebApplicationPbiBoard;Trusted_Connection=True;"))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<WebApplicationPbiBoard.Models.ScrumModels_Mappings.PbiMap>())
                .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
                .CurrentSessionContext("web")
                .BuildSessionFactory();
        }

public class MvcApplication : System.Web.HttpApplication
{
    public static ISessionFactory SessionFactory { get; private set; }
    protected void Application_Start()
    {
        //my additions
        SessionFactory = NHibernateConfigurator.CreateSessionFactory();
    }

    protected void Application_OnEnd()
    {
        SessionFactory.Dispose();
    }

    protected void Application_BeginRequest()
    {
        ISession session = SessionFactory.OpenSession();

        CurrentSessionContext.Bind(session);
    }

    protected void Application_EndRequest()
    {
        CurrentSessionContext.Unbind(SessionFactory);
    }
}

Here’s the relevant snippet from my DataAccessObject, which simply wraps NHibernate CRUD operations:

public class DatabaseAccessObject<T> where T : class
    {
        private readonly ISession session = MvcApplication.SessionFactory.GetCurrentSession();
        private ISession Session { get { return session; } }

        public T Save(T obj)
        {
            ITransaction transaction = null;
            try
            {
                transaction = Session.BeginTransaction();

                Session.SaveOrUpdate(obj);
                transaction.Commit();
                return obj;
            }
            catch (Exception ex)
            {
                if (transaction != null && transaction.IsActive)
                    transaction.Rollback();

                throw;
            }
        }

And finally, here’s the code for my Http-Post edit method:

private readonly DatabaseAccessObject<Sprint> db = new DatabaseAccessObject<Sprint>();
private DatabaseAccessObject<Sprint> Db { get { return db; } }

[HttpPost]
public ActionResult Edit(Sprint editedSprint)
{
    if (ModelState.IsValid)
    {
        Db.Save(editedSprint);
        return RedirectToAction("Index");
    }
    else
        return View(editedSprint);            
 }

Any help would be appreciated.

  • 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-24T23:43:05+00:00Added an answer on May 24, 2026 at 11:43 pm

    The object you’re saving probably hasn’t got the Id set on it.

    SaveOrUpdate does one of two things:
    – Update() if the Id is set.
    – Save() if the Id is not set.

    refer to the docs:
    http://www.nhforge.org/doc/nh/en/index.html

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.