Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@ Licensed under the Apache License, Version 2.0. See License.txt in the project r
<s:Boolean x:Key="/Default/UserDictionary/Words/=unignore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fixup/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=attacher/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Uniquify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

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

32 changes: 17 additions & 15 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -26,7 +28,7 @@ public static class CosmosEntityTypeBuilderExtensions
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder ToContainer(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
Expand All @@ -45,7 +47,7 @@ public static EntityTypeBuilder ToContainer(
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> ToContainer<TEntity>(
[NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
where TEntity : class
=> (EntityTypeBuilder<TEntity>)ToContainer((EntityTypeBuilder)entityTypeBuilder, name);

Expand All @@ -59,9 +61,9 @@ public static EntityTypeBuilder<TEntity> ToContainer<TEntity>(
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder ToContainer(
public static IConventionEntityTypeBuilder? ToContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetContainer(name, fromDataAnnotation))
Expand All @@ -84,7 +86,7 @@ public static IConventionEntityTypeBuilder ToContainer(
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand All @@ -101,7 +103,7 @@ public static bool CanSetContainer(
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static OwnedNavigationBuilder ToJsonProperty(
[NotNull] this OwnedNavigationBuilder entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
{
entityTypeBuilder.OwnedEntityType.SetContainingPropertyName(name);

Expand All @@ -116,7 +118,7 @@ public static OwnedNavigationBuilder ToJsonProperty(
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static OwnedNavigationBuilder<TEntity, TDependentEntity> ToJsonProperty<TEntity, TDependentEntity>(
[NotNull] this OwnedNavigationBuilder<TEntity, TDependentEntity> entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
where TEntity : class
where TDependentEntity : class
{
Expand All @@ -135,9 +137,9 @@ public static OwnedNavigationBuilder<TEntity, TDependentEntity> ToJsonProperty<T
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder ToJsonProperty(
public static IConventionEntityTypeBuilder? ToJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetJsonProperty(name, fromDataAnnotation))
Expand All @@ -160,7 +162,7 @@ public static IConventionEntityTypeBuilder ToJsonProperty(
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand All @@ -177,7 +179,7 @@ public static bool CanSetJsonProperty(
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder HasPartitionKey(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
{
entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name);

Expand All @@ -192,7 +194,7 @@ public static EntityTypeBuilder HasPartitionKey(
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> HasPartitionKey<TEntity>(
[NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
where TEntity : class
{
entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name);
Expand Down Expand Up @@ -228,9 +230,9 @@ public static EntityTypeBuilder<TEntity> HasPartitionKey<TEntity, TProperty>(
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder HasPartitionKey(
public static IConventionEntityTypeBuilder? HasPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetPartitionKey(name, fromDataAnnotation))
Expand All @@ -253,7 +255,7 @@ public static IConventionEntityTypeBuilder HasPartitionKey(
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand Down
36 changes: 19 additions & 17 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -19,13 +21,13 @@ public static class CosmosEntityTypeExtensions
/// </summary>
/// <param name="entityType"> The entity type to get the container name for. </param>
/// <returns> The name of the container to which the entity type is mapped. </returns>
public static string GetContainer([NotNull] this IEntityType entityType)
public static string? GetContainer([NotNull] this IEntityType entityType)
=> entityType.BaseType != null
? entityType.GetRootType().GetContainer()
: (string)entityType[CosmosAnnotationNames.ContainerName]
: (string?)entityType[CosmosAnnotationNames.ContainerName]
?? GetDefaultContainer(entityType);

private static string GetDefaultContainer(IEntityType entityType)
private static string? GetDefaultContainer(IEntityType entityType)
=> entityType.IsOwned()
? null
: entityType.Model.GetDefaultContainer()
Expand All @@ -36,7 +38,7 @@ private static string GetDefaultContainer(IEntityType entityType)
/// </summary>
/// <param name="entityType"> The entity type to set the container name for. </param>
/// <param name="name"> The name to set. </param>
public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)));
Expand All @@ -49,7 +51,7 @@ public static void SetContainer([NotNull] this IMutableEntityType entityType, [C
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetContainer(
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Expand All @@ -70,19 +72,19 @@ public static void SetContainer(
/// </summary>
/// <param name="entityType"> The entity type to get the containing property name for. </param>
/// <returns> The name of the parent property to which the entity type is mapped. </returns>
public static string GetContainingPropertyName([NotNull] this IEntityType entityType)
public static string? GetContainingPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.PropertyName] as string
?? GetDefaultContainingPropertyName(entityType);

private static string GetDefaultContainingPropertyName(IEntityType entityType)
=> entityType.FindOwnership()?.PrincipalToDependent.Name;
private static string? GetDefaultContainingPropertyName(IEntityType entityType)
=> entityType.FindOwnership()?.PrincipalToDependent!.Name;

/// <summary>
/// Sets the name of the parent property to which the entity type is mapped.
/// </summary>
/// <param name="entityType"> The entity type to set the containing property name for. </param>
/// <param name="name"> The name to set. </param>
public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
Check.NullButNotEmpty(name, nameof(name)));
Expand All @@ -95,7 +97,7 @@ public static void SetContainingPropertyName([NotNull] this IMutableEntityType e
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetContainingPropertyName(
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
Expand All @@ -116,15 +118,15 @@ public static void SetContainingPropertyName(
/// </summary>
/// <param name="entityType"> The entity type to get the partition key property name for. </param>
/// <returns> The name of the partition key property. </returns>
public static string GetPartitionKeyPropertyName([NotNull] this IEntityType entityType)
public static string? GetPartitionKeyPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.PartitionKeyName] as string;

/// <summary>
/// Sets the name of the property that is used to store the partition key key.
/// </summary>
/// <param name="entityType"> The entity type to set the partition key property name for. </param>
/// <param name="name"> The name to set. </param>
public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PartitionKeyName,
Check.NullButNotEmpty(name, nameof(name)));
Expand All @@ -137,7 +139,7 @@ public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetPartitionKeyPropertyName(
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PartitionKeyName,
Expand All @@ -158,15 +160,15 @@ public static void SetPartitionKeyPropertyName(
/// </summary>
/// <param name="entityType"> The entity type to get the etag property name for. </param>
/// <returns> The name of the etag property. </returns>
public static string GetETagPropertyName([NotNull] this IEntityType entityType)
public static string? GetETagPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.ETagName] as string;

/// <summary>
/// Sets the name of the property that is used to store the etag key.
/// </summary>
/// <param name="entityType"> The entity type to set the etag property name for. </param>
/// <param name="name"> The name to set. </param>
public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ETagName,
Check.NullButNotEmpty(name, nameof(name)));
Expand All @@ -179,7 +181,7 @@ public static void SetETagPropertyName([NotNull] this IMutableEntityType entityT
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetETagPropertyName(
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ETagName,
Expand All @@ -200,7 +202,7 @@ public static void SetETagPropertyName(
/// </summary>
/// <param name="entityType"> The entity type to get the etag property for. </param>
/// <returns> The <see cref="IProperty" /> mapped to etag, or null if no property is mapped to etag. </returns>
public static IProperty GetETagProperty([NotNull] this IEntityType entityType)
public static IProperty? GetETagProperty([NotNull] this IEntityType entityType)
{
Check.NotNull(entityType, nameof(entityType));
var etagPropertyName = entityType.GetETagPropertyName();
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -23,7 +25,7 @@ public static class CosmosModelBuilderExtensions
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasDefaultContainer(
[NotNull] this ModelBuilder modelBuilder,
[CanBeNull] string name)
[CanBeNull] string? name)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NullButNotEmpty(name, nameof(name));
Expand All @@ -44,9 +46,9 @@ public static ModelBuilder HasDefaultContainer(
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionModelBuilder HasDefaultContainer(
public static IConventionModelBuilder? HasDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!modelBuilder.CanSetDefaultContainer(name, fromDataAnnotation))
Expand All @@ -68,7 +70,7 @@ public static IConventionModelBuilder HasDefaultContainer(
/// <returns> <see langword="true" /> if the given container name can be set as default. </returns>
public static bool CanSetDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
[CanBeNull] string name,
[CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Expand Down
Loading