I have just gotten a very odd error and I can’t explain, or trace it out. My forum entity maintains a list of child forums. The list is internal, and exposed as an ienumerable, along with some methods like AddChild, FindChild and RemoveChild. Now to the code:
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Add(ForumAddModel model, int? forumId = null)
{
ConsumeErrors(validationService.ValidateForumAddModel(model));
if (!ModelState.IsValid) return View(model);
Forum entity = new Forum(model.Title);
entity.Sequence = model.Sequence;
entity.Description = model.Description;
entity.Moderated = model.Moderated;
entity.Enabled = model.Enabled;
entity.Visible = model.Visible;
if (forumId.HasValue)
{
Forum parent = forumRepository.SelectById(forumId.Value);
parent.AddForum(entity);
forumRepository.Update(parent);
return RedirectToAction("Detail", new { id = forumId });
}
else
{
forumRepository.Insert(entity);
return RedirectToAction("Manager");
}
}
I have stepped through this several times, testing values along the way. It works perfectly, so I cannot explain the error. If a parent forum id is given, forumRepository.Update(parent) runs with no errors, it just doesn’t actually save the new child to the db.
Incidentally… until I restart VS2010, the nhibernate session actually THINKS it HAS worked, and the new record shows on the page.
Say whut?