Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating object using NHibernate in Asp.net MVC4
    primarykey
    data
    text
    <p>I have problem in updating object with nhibernate in ASP.Net MVC4 Im doing the update in this scenario:</p> <pre><code>the application loads an object in the first session the object is passed up to the UI tier some modifications are made to the object the object is passed back down to the business logic tier the application persists these modifications by calling SaveOrUpdate() </code></pre> <p>all this happen only in one session. I have static a class name NHibernateSessionPerRequest and its constructor is static (singeleton)</p> <pre><code> [HttpPost] public ActionResult Edit(Menu menu) { if (ModelState.IsValid) { repository.SaveOrUpdate(menu); TempData["message"] = string.Format("{0} has been saved", menu.Name); return RedirectToAction("Index"); } else { // there is something wrong with the data values return View(menu); } } </code></pre> <p>but menu ID is zero. and doesnt have its original ID (id is type of GUID). and SaveOrUpdate() alway treat it as a new object and save it not update it.</p> <p><img src="https://i.stack.imgur.com/rjCfF.jpg" alt="enter image description here"></p> <p>here is Edit.cshtml:</p> <pre><code> @model MyApp.Domain.Entities.MenuComponent @{ ViewBag.Title = "Edit"; Layout = "~/Views/Shared/_AdminLayout.cshtml"; } &lt;h2&gt;Edit @Model.Name &lt;/h2&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;MenuComponent&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Name) @Html.ValidationMessageFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Description) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Description) @Html.ValidationMessageFor(model =&gt; model.Description) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } &lt;div&gt; @Html.ActionLink("Back to List", "Index") &lt;/div&gt; </code></pre> <p>how can I update the object?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload