0

動的に作成して移行のコンテンツ タイプにアタッチしたアタッチ パーツの DateTimeField から DateTime を取得できません。

構造は次のようになります。

CourseDate (ContentType)
   ProductPart (attached part from other project)
   CourseDatePart (attached part)
   TimeSpanPart (attached part from "dynamically" created part)

DateTimeField である StartDateTime と EndDateTime を TimeSpanPart から取り出そうとしています。ただし、DateTime プロパティは常に 1/1/0001 です

値を取得するために使用しているコードは次のとおりです。TimeSpanPart 以外はすべて機能します。

    private EditCourseViewModel BuildEditorViewModel(CoursePart part)
    {
        var courseDates = _contentManager.Query<CourseDatePart, CourseDatePartRecord>().Where(x => x.CourseId == part.Id)
            .List<CourseDatePart>()
            .Select(x =>

                new CourseDateViewModel
                {
                    Id = x.Id,
                    StartDate = ((dynamic) x.ContentItem).TimeSpanPart.StartDateTime.DateTime,
                    EndDate = ((dynamic) x.ContentItem).TimeSpanPart.EndDateTime.DateTime,
                    Sku = ((dynamic) x.ContentItem).ProductPart.Sku,
                    IsDigital = ((dynamic) x.ContentItem).ProductPart.IsDigital,
                    Inventory = x.Inventory
                }

            );

x.Record.ContentItemRecord.Data の値を調べると、必要なデータがあることがわかります。

    <Data><TimeSpanPart><StartDateTime>2013-09-02T06:20:00.0000000</StartDateTime><EndDateTime>2013-09-21T00:05:00.0000000</EndDateTime></TimeSpanPart></Data>

移行の関連部分は次のとおりです。

      ContentDefinitionManager.AlterPartDefinition("TimeSpanPart", part=>part
            .Attachable()
            .WithField("StartDateTime", f=>f.OfType("DateTimeField").WithDisplayName("Start Date Time"))
            .WithField("EndDateTime", f=>f.OfType("DateTimeField").WithDisplayName("End Date Time"))
            );

        ContentDefinitionManager.AlterTypeDefinition("CourseDate", type=>type
            .WithPart(typeof(CourseDatePart).Name)
            .WithPart("TimeSpanPart")
            .WithPart(typeof(ProductPart).Name)
            );

編集:

フィールドのストレージを管理する Orchard InfosetStorageProvider クラスをもう少し掘り下げました。BindStorage メソッドでは、Data XML 要素を Get メソッドに渡しています。しかし、infosetPart.Infoset.Element (上に示したデータが必要です) を渡す代わりに、null ではないため、infosetPart.ContentItem.VersionRecord を渡しています。代わりに空の XML 要素です: <Data />

 return new SimpleFieldStorage(
                (name, valueType) => Get(infosetPart.ContentItem.VersionRecord == null ? infosetPart.Infoset.Element : infosetPart.VersionInfoset.Element, partName, fieldName, name),
                (name, valueType, value) => Set(infosetPart.ContentItem.VersionRecord == null ? infosetPart.Infoset.Element : infosetPart.VersionInfoset.Element, partName, fieldName, name, value));
        }

データを infosetPart.ContentItem.VersionRecord に正しく入力するにはどうすればよいですか? これは、null の代わりに空の xml <Data /> 要素を渡して、代わりに infosetPart.Infoset.Element を Get メソッドに渡すという Orchard のバグですか、それとも何か間違っていますか? infosetPart.ContentItem.VersionRecord と infosetPart.Infoset.Element の違いがわかりません。

4

1 に答える 1

0

問題は、コンテンツ アイテムを作成するときに、コンテンツ アイテムを作成する前にフィールドの値を設定していたことです。このため、Orchard_Framework_ContentItemVersionRecord ではなく、テーブル Orchard_Framework_ContentItemRecord に値を入れていました。

Piedone によって報告され、Sebastien Ros によって閉じられた「バグ」については、こちらを参照してください

オブジェクトを作成した後に値を設定することは考えもしませんでした。テーブル ContentItemVersionRecord の値が <Data /> ではなく NULL に設定されていた場合、それは機能していたはずであるという点で、まだ何かが正しくないようです。

前:

            var courseDate = _contentManager.New("CourseDate");

            var courseDatePart = courseDate.As<CourseDatePart>();

            courseDatePart.CourseId = coursePart.Id;
            courseDatePart.Inventory = newDate.Inventory;

            dynamic courseDateDyn = courseDate;

            courseDateDyn.TimeSpanPart.StartDateTime.DateTime = newDate.StartDate.Value;
            courseDateDyn.TimeSpanPart.EndDateTime.DateTime = newDate.EndDate.Value;

            var product = courseDate.As<ProductPart>();

            product.Sku = newDate.Sku;
            product.IsDigital = newDate.IsDigital;

            //This should move up before setting field values.
            _contentManager.Create(courseDate);

後:

            var courseDate = _contentManager.New("CourseDate");

            var courseDatePart = courseDate.As<CourseDatePart>();

            courseDatePart.CourseId = coursePart.Id;
            courseDatePart.Inventory = newDate.Inventory;

            //This needs to happen before we set any values on the fields.
            _contentManager.Create(courseDate);

            dynamic courseDateDyn = courseDate;

            courseDateDyn.TimeSpanPart.StartDateTime.DateTime = newDate.StartDate.Value;
            courseDateDyn.TimeSpanPart.EndDateTime.DateTime = newDate.EndDate.Value;

            var product = courseDate.As<ProductPart>();

            product.Sku = newDate.Sku;
            product.IsDigital = newDate.IsDigital;
于 2013-09-19T05:49:26.667 に答える