Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.58k forks source link

[QUERY] Why can't I set a UniqueKeyPolicy in CosmosDBSqlContainerResourceInfo? #45293

Closed dbeyda closed 3 weeks ago

dbeyda commented 1 month ago

Library name and version

Azure.ResourceManager.CosmosDB 1.3.2.0

Query/Question

Hello! I'm at a codebase where we use ContainerCollection.CreateOrUpdateAsync to create or update our containers.

Notice this method receives a CosmosDBSqlContainerCreateOrUpdateContent , which contains a CosmosDBSqlContainerResourceInfo. ContainerResourceInfo class allows me to set some updatable properties (index, TTL), and also some properties that are only set during container creation (partition key for ex.).

However, I cannot set the UniqueKeys / UniqueKeyPolicy. If you look at code, UniqueKeyPolicy is internal.

Is there any way I can set this field? If no, is there any particular reason to forbidding outside devs from setting this field?

Thanks a lot!

Environment

Windows 11 / .NET 8.0.303

github-actions[bot] commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

dbeyda commented 1 month ago

Found the factory method I can use to set UniqueKey field! Thanks! @ArthurMa1978 Feel free to mark as resolved.

HarveyLink commented 3 weeks ago

@dbeyda Thank you for using Azure SDK for .NET. Looks like you have work around this issue using Mock. Actually, you could use this property: https://github.com/Azure/azure-sdk-for-net/blob/f03114b97bea85b9028e1a4850270a2e7de2bf3d/sdk/cosmosdb/Azure.ResourceManager.CosmosDB/src/Generated/Models/CosmosDBSqlContainerResourceInfo.cs#L102 This will set the internal property UniqueKeyPolicy you would like to use. It's by design.