1

为什么 ContentItem 中不包含无字段 ContentPart?

以下是 Migrations.cs 中的代码:

SchemaBuilder.CreateTable("ImageDescribedPartRecord", 
                table => table.ContentPartRecord());

ContentDefinitionManager.AlterPartDefinition(
                "ImageDescribedPart",
                cpd => cpd.WithField(
                    "Image",
                    b => b
                             .OfType("MediaPickerField")
                             .WithSetting("MediaPickerFieldSettings.Required", "false")));

ContentDefinitionManager.AlterTypeDefinition(
                "PlantPicture",
                cfg => cfg
                           .WithPart("ImageDescribedPart")
                           .WithPart("CommonPart", p => p.WithSetting("OwnerEditorSettings.ShowOwnerEditor", "false"))
                           .WithPart("BodyPart")
                           .WithPart("TitlePart")
                           .WithPart("AutoroutePart"
                                     , builder =>
                                       builder
                                           .WithSetting("AutorouteSettings.AllowCustomPattern", "false")
                                           .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "true")
                                           .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Container', Pattern: '{Content.Container.Path}/images/{Content.Slug}', Description: 'apgii/taxon/sub-taxon/images/title'}]")
                                           .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
                           .WithPart("ContainablePart")
                           .Creatable(true)
                    // todo: The following doesn't work. Make it work.
                           .WithSetting("BodyPartSettings.FlavorDefault", "text") 
                           );

以下是 ContentPart 的代码:

public class ImageDescribedPart : ContentPart<ImageDescribedPartRecord>{

    }

 public class ImageDescribedPartRecord :ContentPartRecord {}

以下代码来自驱动程序

IContentQuery<ContentItem> query = _contentManager
     .Query(VersionOptions.Published)
    .Join<CommonPartRecord>()
    .Where(cr => cr.Container.Id == container.Id);
var items = query.Slice(0, 10).ToList();

IEnumerable<Zulatm.WebPlants.Models.ImageDescribedPart> firstImages = items.AsPart<ImageDescribedPart>();

Logger.Debug("Items count: {0}", items.Count());
for (int i = 0; i < items.Count(); i++) {
    Logger.Debug("Item {0}: {1}", i, items[i].As<TitlePart>().Title);

}
Logger.Debug("Images count: {0}",firstImages.Count());

返回以下内容

2012-12-07 16:28:45,616 [35] TaxonomyNodePartDriver - Items count: 2
2012-12-07 16:28:45,617 [35] TaxonomyNodePartDriver - Item 0: Test
2012-12-07 16:28:45,619 [35] TaxonomyNodePartDriver - Item 1: test img 2
2012-12-07 16:28:45,619 [35] TaxonomyNodePartDriver - Images count: 0
4

2 回答 2

1

您将项目“投射”到零件并将其存储为 IEnumerable。我想知道这如何不会导致编译错误,因为这是错误的。

您的问题的根源很可能是,如果您打算通过“铸造”直接使用零件,则该零件应该有相应的驱动程序(可以为空)。

于 2012-12-07T14:37:33.680 回答
1

好的。问题是处理程序中没有添加过滤器。已添加 ActivatorFilter:

public ImageDescribedHandler (IRepository<ImageDescribedPartRecord> repository,      INavigationManager navigationManager)
{
    Filters.Add(new ActivatingFilter<ImageDescribedPart>("PlantPicture"));
}

还删除了创建表的行。

于 2012-12-07T14:55:41.883 回答