Markus, thanks for helping... whilst there is still an underlying issue with the object trying to persist itself back to the DB when being automapped. The connection issue was actually caused by one of the validators closing a session as part of a detached query
Sorry for false alarm... just unpicking a few issues, I should have put my TDD hat on first On Jul 3, 2:18 pm, Markus Zywitza <[email protected]> wrote: > Can you verify that a sessionscoep is created in your controller: > > Debug.Assert(SessionScope.Current != null); > > -Markus > > 2009/7/3 David E <[email protected]> > > > > > Hi when the following code is run with Lazy loading off everything is > > fine > > > [ValidateModel(typeof (ArticleEditDto)), AcceptVerbs > > (HttpVerbs.Post)] > > [ValidateInput(false)] //so that can pass html for body > > into action > > public ActionResult Save(ArticleEditDto form) > > { > > if (ViewData.ModelState.IsValid) > > { > > return SaveContent(form, article => > > RedirectToAction<NewsController>(c => c.Index(null)), > > PopulateIdentities); > > } > > return Edit(articleMapper.Map(form)); > > } > > > When I implement ar.sessionscope in web.config I get a session is > > closed error > > > After some digging I found that the first call to > > `ViewData.ModelState.IsValid` calls the database without issue but > > then it appears that the session gets closed before the > > articleMapper.Map(form) is called (if invalid) > > > If I put the following code together > > > [ValidateModel(typeof (ArticleEditDto)), AcceptVerbs > > (HttpVerbs.Post)] > > [ValidateInput(false)] //so that can pass html for body into > > action > > public ActionResult Save(ArticleEditDto form) > > { > > if (ViewData.ModelState.IsValid) > > { > > using (new SessionScope()) > > return SaveContent(form, article => > > RedirectToAction<NewsController>(c => c.Index(null)), > > PopulateIdentities); > > } > > using(new SessionScope()) > > return Edit(articleMapper.Map(form)); > > } > > > I get an error about updating the underlying class? This is very odd > > as I am using ActiveRecordMediator as follows and at no time trying to > > update the class? > > > public ActionResult Edit(Article form) > > { > > int articleTypeId = form.ArticleType == null ? 0 : > > form.ArticleType.Id <http://form.articletype.id/>; > > PopulateDropdowns(form, articleTypeId); > > return View("Edit", articleMapper.Map(form)); > > } > > > public virtual TDto Map(TModel model) > > { > > model = model.Id > 0 ? repository.FindByPrimaryKey(model.Id) : > > new TModel(); > > return Map<TDto>(model); > > } > > > public new T FindByPrimaryKey(object id) > > { > > return ActiveRecordMediator<T>.FindByPrimaryKey(id); > > } > > > Sorry this post is so long but I am really stuck on why this is > > happening > > > Can post lots more info or errors if needed > > > Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
