読み込み設定
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
この SDK と Stylelabs.M.Base.Querying
は、読み込み設定と読み込みオプションを使用して以下の各設定を指定します。
- エンティティを読み込む必要があるかどうか
- どのカルチャにエンティティを読み込む必要があるか
- どのメンバーでエンティティを読み込むか
[!注] 読み込み設定は にあります。
Stylelabs.M.Framework.Essentials.LoadConfigurations
. 読み込みオプションはStylelabs.M.Framework.Essentials.LoadOptions
にあります。ヒント サーバーに対するオーバーヘッドを最小限に抑えるために、読み込みオプションと読み込み設定を使用して最小限の量のデータを読み込むようにします。
このセクションでは、最初にさまざまな読み込みオプションについて説明し、次に読み込みオプションを指定して読み込み設定を使用する方法を紹介します。
読み込みオプション
読み込みオプションは、特定のアイテムを読み込む方法を指定する "atomic 単位" です。 現在サポートされている読み込みオプションは次のとおりです。
- カルチャ読み込みオプション
- プロパティ読み込みオプション
- リレーション読み込みオプション
どの読み込みオプションにも、一般的なユース ケース向けとして、既定のインスタンス、静的インスタンス、および読み取り専用インスタンスがあります。 また、読み込みオプションにはコピー コンストラクターもあります。 このコンストラクターを使用すると、読み取り専用の読み込みオプションをコピーして変更できます。
上記のすべての読み込みオプション クラスには、次の値を指定できる LoadOption
(列挙型) プロパティがあります。
- なし
- 既定
- カスタム
- すべて
Custom
に設定した場合、このオブジェクトでは、PropertyLoadOption
のプロパティ名のリストを提供して、何を読み込むかを指定する必要があります。 LoadOption
を Custom
に設定していない場合、このリストは無視されます。
カルチャ読み込みオプション
既定のカルチャ読み込みオプションは次のとおりです。
CultureLoadOption.All
: Sitecore Content Hub に登録されているすべてのカルチャを読み込みます。CultureLoadOption.Default
: Sitecore Content Hub で既定のカルチャを読み込みます。CultureLoadOption.None
: カルチャを読み込みません。
[!注] カルチャを指定せずにエンティティを読み込むと、そのエンティティにはカルチャに依存するプロパティが存在しません。
特定の複数のカルチャでエンティティを読み込むと、カルチャに依存するプロパティはそれらのカルチャでのみ使用できます。
特定の複数のカルチャを読み込むには、次のいずれかの方法を使用して新しい CultureLoadOption
を作成します。
-
ロケール識別子 (LCID) をコンマ区切りで渡す。
RequestResponsenew CultureLoadOption("en-US", "nl-BE");
-
By passing any type of collection (deriving from
IEnumerable
) of locale identifiers (LCID):RequestResponsestring[] cultures = new [] {"en-US", "nl-BE"}; new CultureLoadOption(cultures);
-
By passing
CultureInfo
instances (comma separated):RequestResponsenew CultureLoadOption(CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("nl-BE"));
-
By passing any type of collection (deriving from
IEnumerable
) ofCultureInfo
instances:RequestResponseCultureInfo[] cultures = new [] {CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("nl-BE")}; new CultureLoadOption(cultures);
Property load option
The following are the default property load options:
PropertyLoadOption.All
: loads all properties on the entity.PropertyLoadOption.None
: loads no properties on the entity.
To load a specific set of properties, create a new PropertyLoadOption
using one of the following methods :
-
By passing the property names (comma separated):
RequestResponsenew PropertyLoadOption("propertyName1", "propertyName2");
-
By passing any type of collection (deriving from
IEnumerable
) of property names:RequestResponsestring[] names = new [] {"propertyName1", "propertyName2"}; new PropertyLoadOption(names);
Relation load option
The following are the default relation load options:
RelationLoadOption.All
: loads all relations on the entity.RelationLoadOption.None
: loads no relations on the entity.
To load a specific set of relations, create a new RelationLoadOption
using one of the following methods :
-
By passing the relation names (comma separated):
RequestResponsenew RelationLoadOption("relationName1", "relationName2");
-
By passing any type of collection (deriving from
IEnumerable
) of relation names:RequestResponsestring[] names = new [] {"relationName1", "relationName2"}; new RelationLoadOption(names);
In order to specify which role to load (e.g. load self-referencing relations), create RelationSpecification
objects using one of the following methods:
-
By passing relation specifications comma separated:
RequestResponseRelationSpecification spec1 = new RelationSpecification { Name = "childSelfReferencingRelation", Role = RelationRole.Child }; RelationSpecification spec2 = new RelationSpecification { Name = "paentSelfReferencingRelation", Role = RelationRole.Parent }; new RelationLoadOption(spec1, spec2);
-
By passing any type of collection (deriving from
IEnumerable
) of relation specifications:RequestResponseRelationSpecification[] specs = new [] {spec1, spec2}; new RelationLoadOption(specs);
Load configurations
Loading configurations are a "molecular unit" which aggregates multiple load options.
Loading configurations also have default configuration values and support copy constructors.
Previously the IQueryLoadConfiguration
was mentioned here, but since the split of the Query and LoadConfiguration, the IQueryLoadConfiguration
should only be used internally in the SDK.
Entity load configuration
The configuration consists of:
CultureLoadOption
PropertyLoadOption
RelationLoadOption
The following are the default entity loading configurations :
EntityLoadConfiguration.Minimal
: loads entities without any cultures, properties and relations. Only system properties are available (id, definition, created on, created by...).EntityLoadConfiguration.Default
: loads entities in the default culture, all properties and no relations.EntityLoadConfiguration.DefaultCultureFull
: loads entities in the default culture, with all properties and all relations.EntityLoadConfiguration.Full
: loads entities in all cultures, all properties and all relations.
A Custom configuration is created in the following method :
new EntityLoadConfiguration(
CultureLoadOption.None,
new PropertyLoadOption("Title", "FileName"),
new RelationLoadOption("AssetTypeToAsset")
);
この例では、カルチャは指定せず、Title
プロパティ、FileName
プロパティ、および AssetTypeToAsset
リレーションを指定してエンティティを読み込みます。
[!注] コンストラクターの代わりにプロパティを使用して読み込みオプションを設定することもできます。
[!注]
EntityLoadConfiguration
を指定しない場合、この SDK では必ず既定のDefault
設定が使用されます。
エンティティの読み込み設定ビルダー
IEntityLoadConfiguration
には、読み込み設定の作成と拡張を容易にするビルダーが付属しています。
次の例では、最小限の読み込み設定から開始し、2 つのリレーションを追加します。
var loadConfig = EntityLoadConfiguration.Minimal.Builder().WithRelations(new[] { "Relation1", "Relation2" }).Build();
この行は次の各部分で構成されています。
EntityLoadConfiguration.Minimal
: 用意されている既定の読み込み設定から開始します。Builder()
: 新しい設定を構築するにはビルダーを取得する必要があります。WithRelations(new[] { "Relation1", "Relation2" })
: ビルダーで読み込み設定を変更します。 この部分は、他のどのビルダー メソッドともチェーン化できます。.Build()
: 最後に構築プロセスを終了すると、最終的な読み込み設定が得られます。