![](/img/trans.png)
[英]Autofac: Is there any way to get an existing LifetimeScope from the Container so I can avoid passing its reference around?
[英]How can I get the ContainerProperties with Indexes from an existing container in CosmosDB
我創建了一個具有容器屬性的容器,並且此ContainerProperties
包含索引。
以后如何從波斯菊找回ContainerProperties
。 我使用以下代碼:
FeedIterator<ContainerProperties> resultSet = CosmosDatabase.GetContainerQueryIterator<ContainerProperties>( ($"select * from c where c.id = \"{collectionName}\"") );
FeedResponse<ContainerProperties> queryProperties = resultSet.ReadNextAsync().Result;
ContainerProperties containerProperties = queryProperties.Resource.ToList().FirstOrDefault()
有一個ContainerProperties
並且名稱正確填充,這就是我想要的,但是索引為空。 containerProperties.IndexingPolicy.IncludedPaths
和containerProperties.IndexingPolicy.ExcludedPaths
不包含任何元素。 但是當我創建它時,它確實可以。
根據評論,您使用的是SDK的預覽版,請更新至最新的GA版本 ,目前為3.0.0
。
在該版本上,運行共享的代碼,將返回已填充IndexingPolicy的ContainerProperties
實例。
ContainerProperties containerDefinition = new ContainerProperties(new Guid().ToString(), "/id");
containerDefinition.IndexingPolicy.ExcludedPaths.Add(new Cosmos.ExcludedPath()
{
Path = "/*"
});
ContainerResponse response = await cosmosDatabase.CreateContainerAsync(containerDefinition);
FeedIterator<ContainerProperties> resultSet = cosmosDatabase.GetContainerQueryIterator<ContainerProperties>(($"select * from c where c.id = \"{response.Container.Id}\""));
FeedResponse<ContainerProperties> queryProperties = resultSet.ReadNextAsync().Result;
ContainerProperties containerSettings = queryProperties.Resource.ToList().FirstOrDefault();
Assert.AreEqual(containerDefinition.IndexingPolicy.ExcludedPaths.First().Path, containerSettings.IndexingPolicy.ExcludedPaths.First().Path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.