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.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---