果园cms内容部分,字段被添加两次,无法删除

时间:2016-01-26 13:36:24

标签: c# asp.net orchardcms orchardcms-1.9

我在内容部分添加了一个简单的字段

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;

它已经添加了两次,现在我无法通过另一次迁移或通过后台办公室将其删除。这是堆栈跟踪

  

发生了未处理的异常,请求已终止。请刷新页面。如果错误仍然存​​在,请返回   Sequence包含多个匹配元素   System.InvalidOperationException:Sequence在System.Linq.Enumerable.SingleOrDefault [TSource](IEnumerable 1 source, Func 2谓词)中包含多个匹配元素,位于C中的Orchard.ContentManagement.MetaData.Builders.ContentPartDefinitionBuilder.RemoveField(String fieldName) :\\开发\ FE-Corporate \ src \ Orchard \ ContentManagement \ MetaData \ Builders \ ContentPartDefinitionBuilder.cs:Orchard.ContentTypes.Services.ContentDefinitionService的第46行。&lt;&gt; c__DisplayClass48.b__47(ContentPartDefinitionBuilder typeBuilder)位于Orchard.ContentManagement.MetaData System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod中的.ContentDefinitionManagerExtensions.AlterPartDefinition(IContentDefinitionManager manager,String name,Action 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个parameters)(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.AsyncControllerActionIn上的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()处于System.Web上System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。&lt;&gt; c__DisplayClass46.b__3f()的System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()中的voker.EndInvokeActionMethod(IAsyncResult asyncResult)。 System.Web.Mvc.Async.AsyncControllerActionInvoker上的System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。&lt;&gt; c__DisplayClass46.b__3f()中的Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。&lt;&gt; c__DisplayClass46.b__3f()。 AsyncInvocationWithFilters&LT;&GT; c__DisplayClass46.b__3f()

1 个答案:

答案 0 :(得分: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;
    }