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

Don't validate partition keys on embedded entity types. #17535

Merged
merged 1 commit into from
Sep 3, 2019
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
6 changes: 4 additions & 2 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public static string GetCosmosContainer([NotNull] this IEntityType entityType) =
?? GetCosmosDefaultContainer(entityType);

private static string GetCosmosDefaultContainer(IEntityType entityType)
=> entityType.Model.GetCosmosDefaultContainer()
?? entityType.ShortName();
=> entityType.IsOwned()
? null
: entityType.Model.GetCosmosDefaultContainer()
?? entityType.ShortName();

/// <summary>
/// Sets the name of the container to which the entity type is mapped.
Expand Down
4 changes: 4 additions & 0 deletions src/EFCore.Cosmos/Internal/CosmosModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ protected virtual void ValidateSharedContainerCompatibility(
foreach (var entityType in model.GetEntityTypes().Where(et => et.FindPrimaryKey() != null))
{
var container = entityType.GetCosmosContainer();
if (container == null)
{
continue;
}

if (!containers.TryGetValue(container, out var mappedTypes))
{
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Properties/CosmosStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<value>The entity type '{entityType}' is sharing the container '{container}' with other types, but does not have a discriminator value configured.</value>
</data>
<data name="NoPartitionKey" xml:space="preserve">
<value>The entity type '{entityType}' does not have a partition key set, but it is mapped to the collection '{collection}' shared by entity types with partition keys.</value>
<value>The entity type '{entityType}' does not have a partition key set, but it is mapped to the container '{container}' shared by entity types with partition keys.</value>
</data>
<data name="OrphanedNestedDocument" xml:space="preserve">
<value>The entity of type '{entityType}' is mapped as a part of the document mapped to '{missingEntityType}', but there is no tracked entity of this type with the corresponding key value. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.</value>
Expand Down
10 changes: 7 additions & 3 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ public virtual bool EnsureCreated()
var created = _cosmosClient.CreateDatabaseIfNotExists();
foreach (var entityType in _model.GetEntityTypes())
{
created |= _cosmosClient.CreateContainerIfNotExists(
entityType.GetCosmosContainer(),
GetCosmosPartitionKeyStoreName(entityType));
var containerName = entityType.GetCosmosContainer();
if (containerName != null)
{
created |= _cosmosClient.CreateContainerIfNotExists(
containerName,
GetCosmosPartitionKeyStoreName(entityType));
}
}

if (created)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ private class Order
public int Id { get; set; }
public string PartitionId { get; set; }
public Customer Customer { get; set; }
public OrderDetails OrderDetails { get; set; }
}

[Owned]
private class OrderDetails
{
public string ShippingAddress { get; set; }
}
}
}