Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL not updating database records in MVC 2 application
    primarykey
    data
    text
    <p>Using MVC 2 I have been trying to make this record store project. Creating records work but updating them doesn't. No exceptions are thrown either.</p> <p>I examined getchangeset() right before submitchanges() it shows all zeros.</p> <p>Thanks for your reading and you help :)</p> <p>The Edit view:</p> <pre><code>&lt;% using (Html.BeginForm("Edit", "Song")) { %&gt; &lt;fieldset&gt; &lt;%: Html.HiddenFor(model =&gt; model.SongID) %&gt; &lt;%: Html.HiddenFor(model =&gt; model.DownloadCount) %&gt; &lt;%: Html.HiddenFor(model =&gt; model.Rating) %&gt; &lt;%: Html.HiddenFor(model =&gt; model.TagMapID) %&gt; &lt;div class="editor-label"&gt; &lt;%= Html.LabelFor(model =&gt; model.AlbumID) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%= Html.DropDownListFor(model =&gt; model.AlbumID, DataHelper.getAlbumList(Model.AlbumID)) %&gt; &lt;%= Html.ValidationMessageFor(model =&gt; model.AlbumID) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%= Html.LabelFor(model =&gt; model.FullName) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%= Html.TextBoxFor(model =&gt; model.FullName)%&gt; &lt;%= Html.ValidationMessageFor(model =&gt; model.FullName) %&gt; and so on... </code></pre> <p>Edit function</p> <pre><code>public ActionResult Edit(int id) { try { var model = songRepository.Song.Single(rec =&gt; rec.SongID == id); return View(model); } catch (Exception anyEx) { throw anyEx; //return View("Error") } } </code></pre> <p>Edit post function</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Song model) { try { if (ModelState.IsValid) { songRepository.SaveSong(model); TempData["adminmsg"] = "Song saved"; return RedirectToAction("List", "Song"); } else { TempData["adminmsg"] = "Song not saved"; return View("Edit", model); } } catch (Exception anyEx) { throw anyEx; } } </code></pre> <p>This is what saveSong() looks like in SqlSongRepository</p> <pre><code>public void SaveSong(Song song) { if (song.SongID == 0) { songTable.InsertOnSubmit(song); } else { songTable.Attach(song); songTable.Context.Refresh(RefreshMode.KeepChanges, song); } songTable.Context.SubmitChanges(); } </code></pre> <p>[Context things]</p> <p>This is the context repository</p> <pre><code>public class ContextRepository : IContextRepository { private string connStr; public ContextRepository(string connectionString) { this.connStr = connectionString; } public DataContext MasterContext { get { return new DataContext(connectionString); } } public string connectionString { get { return connStr; } } } </code></pre> <p>In the song controller for example</p> <pre><code>public SongController(IContextRepository contextRepository) { this.contextRepository = contextRepository; MasterContext = this.contextRepository.MasterContext; DataHelper.InitContext(contextRepository); songRepository = new SqlSongRepository(contextRepository.connectionString); } </code></pre> <p>Then the songRepository is used as I posted before.</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