2016-01-26 48 views
0

我添加了一個簡單的字段內容部分果園CMS內容的一部分,現場被添加兩次,不能刪除

ContentDefinitionManager.AlterPartDefinition("CarouselContentPart", b => 
      b 
      .WithField("AutoPlay", cfg => 
       cfg.OfType("NumericField") 
        .WithSetting("NumericFieldSettings.Hint", "Enter a value in milliseconds for autoplay (leave blank for no autoplay)") 
        .WithSetting("NumericFieldSettings.Required", "false") 
        .WithDisplayName("Autoplay")) 
      ); 

     return 18; 

它得到補充兩次,現在我無法將其刪除,或者通過其他的遷移或通過後臺。這是堆棧跟蹤

發生未處理的異常並且請求已終止。請刷新頁面。如果錯誤仍然存​​在,請返回 序列包含多個匹配元素 System.InvalidOperationException:序列在Orchard.ContentManagement.MetaData中的System.Linq.Enumerable.SingleOrDefault [TSource](IEnumerable 1 source, Func 2謂詞)包含多個匹配元素.Builders.ContentPartDefinitionBuilder.RemoveField(String fieldName)在C:\ Development \ FE-Corporate \ src \ Orchard \ ContentManagement \ MetaData \ Builders \ ContentPartDefinitionBuilder.cs中:第46行Orchard.ContentTypes.Services.ContentDefinitionService。 <> c__DisplayClass48.b__47(ContentPartDefinitionBuilder typeBuilder)在Orchard.ContentManagement.MetaData.ContentDefinitionManagerExtensions.AlterPartDefinition(IContentDefinitionManager經理,字符串名稱,動作1 alteration) in C:\Development\FE-Corporate\src\Orchard\ContentManagement\MetaData\IContentDefinitionManager.cs:line 32 at Orchard.ContentTypes.Services.ContentDefinitionService.RemoveFieldFromPart(String fieldName, String partName) at Orchard.ContentTypes.Controllers.AdminController.RemoveFieldFromPOST(String id) at lambda_method(Closure , ControllerBase , Object[]) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2參數)在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary的2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult)在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)at System.Web.Mvc.Async。在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters的AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()<> c__DisplayClass46.b__3f> c__DisplayClass46.b__3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。 <> c__DisplayClass46.b__3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。 <> c__DisplayClass46.b__3f()

+0

貌似代碼期望只有一個字段,不能與多個工作。我想你唯一的選擇是從字段附加的數據庫中刪除一些記錄 – devqon

回答

0

如果您的新內容部分中沒有任何重要數據,那麼您可以嘗試使用遷移進行刪除和重新創建。

這會讓你失去爲內容部分保存的所有數據,但也會給你一個乾淨休息的機會。

您可以刪除內容部分是這樣的:

public int UpdateFrom18() { 
     // remove the CarouselContentPart part cleanly 
     ContentDefinitionManager.DeletePartDefinition(typeof (CarouselContentPart).Name); 
enter code here 
     // re-add the CarouselContentPart again 
     // NOTE: Change this bit to add include whatever you have created in your previous 17 migrations such as setting up the part and adding fields 
     ContentDefinitionManager.AlterPartDefinition(typeof (CarouselContentPart).Name, 
      cfg = > cfg 
      .Attachable() 
      .WithDescription("Some kind of description, etc")); 
     return 4; 
    }