diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs index 93bfa0aade..b4383d8fb0 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs @@ -32,6 +32,11 @@ public abstract class Container /// public abstract string Id { get; } + /// + /// Returns the parent Database reference + /// + public abstract Database Database { get; } + /// /// Returns the conflicts /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs index 2cda57c13a..fa5820e1a7 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs @@ -17,8 +17,6 @@ namespace Microsoft.Azure.Cosmos internal abstract class ContainerInternal : Container { - public abstract Database Database { get; } - internal abstract Uri LinkUri { get; } internal abstract CosmosClientContext ClientContext { get; } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs index efd1b06cce..82f0ff109b 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos /// /// Operations for reading or deleting an existing database. /// - /// See for creating new databases, and reading/querying all databases; use `client.Databases`. + /// See for creating new databases, and reading/querying all databases; use `client.Databases`. /// /// /// Note: all these operations make calls against a fixed budget. @@ -27,6 +27,11 @@ public abstract class Database /// public abstract string Id { get; } + /// + /// The parent Cosmos client instance related the database instance + /// + public abstract CosmosClient Client { get; } + /// /// Reads a from the Azure Cosmos service as an asynchronous operation. /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs index 234f2465cd..0717edee54 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs @@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos /// /// Operations for reading or deleting an existing database. /// - /// for or creating new databases, and reading/querying all databases; use `client.Databases`. + /// for or creating new databases, and reading/querying all databases; use `client.Databases`. /// internal class DatabaseCore : DatabaseInternal { @@ -34,6 +34,8 @@ protected DatabaseCore( public override string Id { get; } + public override CosmosClient Client => this.ClientContext.Client; + internal override Uri LinkUri { get; } internal override CosmosClientContext ClientContext { get; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index c70e3643ac..0de61a205c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -57,6 +57,13 @@ public async Task Cleanup() await base.TestCleanup(); } + [TestMethod] + public void ParentResourceTest() + { + Assert.AreEqual(this.database, this.Container.Database); + Assert.AreEqual(this.cosmosClient, this.Container.Database.Client); + } + [TestMethod] public async Task CreateDropItemTest() { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json index a5b1ffb912..1c23f908ea 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json @@ -677,6 +677,16 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.Database Database": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.Database get_Database()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Database get_Database()" + }, "Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": { "Type": "Method", "Attributes": [], @@ -2015,6 +2025,16 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.Container GetContainer(System.String)" }, + "Microsoft.Azure.Cosmos.CosmosClient Client": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosClient get_Client()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosClient get_Client()" + }, "Microsoft.Azure.Cosmos.FeedIterator GetContainerQueryStreamIterator(Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": { "Type": "Method", "Attributes": [],