Hi Fabio,

Given that I am new to all of the pieces used in the this project with
some being new pieces in themselves, I guess it'd be a good way to
isolate the problem. Let try it in pure NH and MVC. I'll report back
with the results.


On Apr 22, 5:34 pm, Fabio Maulo <[email protected]> wrote:
> Can you recreate the issue using pure NH ?
>
> 2009/4/22 fmester <[email protected]>
>
>
>
>
>
> > What is trully bizarre is that this update problem occurs without any
> > errors. I expect to be able to update an entity and save it to the
> > database, but for some reason it never makes it that far. BTW, Insert
> > and Delete for the same entity work just fine.
>
> > With another entity which has no relationships to any others, it all
> > works just fine.
>
> > Here's the setup:
>
> > I am using ASP.NET MVC, S#arp Architecture, Fluent NHibernate and
> > NHibernate for this project.
>
> > I have 2 related tables in the database:
>
> > ---------------------------------------------------------------------------------------------------
> > DocumentType { DocumentTypeID, DocumentTypeDescription }
> > Document { DocumentID, DocumentTypeID, DocumentName }
>
> > I have modelled them as:
>
> > - DocumentType -
> > public DocumentType() { }
> > public virtual string DocumentTypeName { get; set; }
> > public virtual IList<Document> Document { get; set; }
>
> > - Document -
> > public Document() { }
> > public Document(string description, DocumentType documentType):this()
> > {
> >            DocumentType = documentType;
> >            Description = description;
> >        }
> > public virtual string DocumentName { get; set; }
> > public virtual DocumentType DocumentType { get; set; }
>
> > The Fluent NHibernate Mappings look like:
>
> > - DocumentType -
> > public void Override( AutoMap<DocumentType> mapping )
> >        {
> >            mapping.WithTable("DocumentType");
> >            mapping.SetAttribute("mutable", "false");
>
> >            mapping.Id( x => x.Id, "DocumentTypeID" )
> >                .WithUnsavedValue( 0 )
> >                .GeneratedBy.Identity();
>
> >            mapping.Map( x => x.DocumentTypeDescription );
>
> >            mapping.HasMany( x => x.Document )
> >                .Inverse()
> >                .WithTableName( "Document" )
> >                .WithKeyColumn( "DocumentID" ).AsBag()
> >                .Cascade.All().AsList();
> >        }
>
> > - Document -
> > public void Override( AutoMap<Document> mapping )
> >        {
> >            mapping.Id( x => x.Id, "DocumentID" )
> >                .WithUnsavedValue( 0 )
> >                .GeneratedBy.Identity();
>
> >            mapping.Map( x => x.DocumentName );
>
> >            mapping.References( x => x.DocumentType,
> > "DocumentTypeID" )
> >                .SetAttribute( "not-null", "true" );
> >        }
>
> > -------------------------------------------------------------------------------------
>
> > Here's my DocumentTypeController Edit ActionResult:
>
> > [Authorize]
> > [ValidateAntiForgeryToken]
> > [Transaction]
> > [AcceptVerbs( HttpVerbs.Post )]
> > public ActionResult Edit( int id, [ModelBinder( typeof
> > ( DefaultModelBinder ) )] DocumentType documentType )
> >        {
> >            DocumentType documentTypeToUpdate =
> > documentTypeRepository.Get( id );
>
> >            documentTypeToUpdate.DocumentTypeName =
> > documentType.DocumentTypeName;
> >            documentTypeToUpdate.DocumentTypeDescription =
> > documentType.DocumentTypeDescription;
>
> >            documentTypeRepository.SaveOrUpdate
> > ( documentTypeToUpdate );
>
> >            TempData["message"] = "The documentType was successfully
> > updated.";
> >            return RedirectToAction( "Index" );
> >        }
>
> > ----------------------------------------------------------------------------------------------------------
> > As you can see from the code in the Edit ActionResult, that I am
> > getting the entity to update using the Get method which is then
> > updated with new values provided by the form.
>
> > The [Transaction] attribute on the Edit method supposedly takes care
> > of the Commit, but it really doesn't.
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to