Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container: Add a database reference to the container #1457

Merged
merged 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public abstract class Container
/// </summary>
public abstract string Id { get; }

/// <summary>
/// Returns the parent Database reference
/// </summary>
public abstract Database Database { get; }

/// <summary>
/// Returns the conflicts
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 6 additions & 1 deletion Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Operations for reading or deleting an existing database.
///
/// See <see cref="CosmosClient"/> for creating new databases, and reading/querying all databases; use `client.Databases`.
/// See <see cref="Client"/> for creating new databases, and reading/querying all databases; use `client.Databases`.
/// </summary>
/// <remarks>
/// Note: all these operations make calls against a fixed budget.
Expand All @@ -27,6 +27,11 @@ public abstract class Database
/// </summary>
public abstract string Id { get; }

/// <summary>
/// The parent Cosmos client instance related the database instance
/// </summary>
public abstract CosmosClient Client { get; }

/// <summary>
/// Reads a <see cref="DatabaseProperties"/> from the Azure Cosmos service as an asynchronous operation.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Operations for reading or deleting an existing database.
///
/// <see cref="CosmosClient"/> for or creating new databases, and reading/querying all databases; use `client.Databases`.
/// <see cref="Client"/> for or creating new databases, and reading/querying all databases; use `client.Databases`.
/// </summary>
internal class DatabaseCore : DatabaseInternal
{
Expand All @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down