Fixing AutoFlush exception when creating content items

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-28 12:19:05 -08:00
parent 4f77fab77a
commit 83e4392f02

View File

@@ -462,7 +462,7 @@ namespace Orchard.ContentManagement {
// produce root record to determine the model id
contentItem.VersionRecord = new ContentItemVersionRecord {
ContentItemRecord = new ContentItemRecord {
ContentType = AcquireContentTypeRecord(contentItem.ContentType)
},
Number = 1,
Latest = true,
@@ -486,15 +486,19 @@ namespace Orchard.ContentManagement {
_contentItemRepository.Create(contentItem.Record);
_contentItemVersionRepository.Create(contentItem.VersionRecord);
// build a context with the initialized instance to create
var context = new CreateContentContext(contentItem);
// invoke handlers to add information to persistent stores
Handlers.Invoke(handler => handler.Creating(context), Logger);
// deferring the assignment of ContentType as loading a Record might force NHibernate to AutoFlush
// the ContentPart, and needs the ContentItemRecord to be created before (created in previous statement)
contentItem.VersionRecord.ContentItemRecord.ContentType = AcquireContentTypeRecord(contentItem.ContentType);
Handlers.Invoke(handler => handler.Created(context), Logger);
if (options.IsPublished) {
var publishContext = new PublishContentContext(contentItem, null);