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

Code cleanup for database providers #22185

Merged
1 commit merged into from
Aug 23, 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
4 changes: 3 additions & 1 deletion src/EFCore.Cosmos/Diagnostics/CosmosEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private enum Id
}

private static readonly string _queryPrefix = DbLoggerCategory.Query.Name + ".";
private static EventId MakeQueryId(Id id) => new EventId((int)id, _queryPrefix + id);

private static EventId MakeQueryId(Id id)
=> new EventId((int)id, _queryPrefix + id);

/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static DbContextOptionsBuilder UseCosmos(
Check.NotEmpty(databaseName, nameof(databaseName));

var extension = optionsBuilder.Options.FindExtension<CosmosOptionsExtension>()
?? new CosmosOptionsExtension();
?? new CosmosOptionsExtension();

extension = extension
.WithAccountEndpoint(accountEndpoint)
Expand Down Expand Up @@ -115,7 +115,7 @@ public static DbContextOptionsBuilder UseCosmos(
Check.NotNull(databaseName, nameof(databaseName));

var extension = optionsBuilder.Options.FindExtension<CosmosOptionsExtension>()
?? new CosmosOptionsExtension();
?? new CosmosOptionsExtension();

extension = extension
.WithConnectionString(connectionString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static IConventionEntityTypeBuilder ToContainer(
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
Expand Down Expand Up @@ -157,7 +159,9 @@ public static IConventionEntityTypeBuilder ToJsonProperty(
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
Expand Down Expand Up @@ -248,7 +252,9 @@ public static IConventionEntityTypeBuilder HasPartitionKey(
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <see langword="true" /> if the configuration can be applied. </returns>
public static bool CanSetPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
Expand Down
34 changes: 21 additions & 13 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ 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) =>
entityType.BaseType != null
public static string GetContainer([NotNull] this IEntityType entityType)
=> entityType.BaseType != null
? entityType.GetRootType().GetContainer()
: (string)entityType[CosmosAnnotationNames.ContainerName]
?? GetDefaultContainer(entityType);
?? GetDefaultContainer(entityType);

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

/// <summary>
/// Sets the name of the container to which the entity type is mapped.
Expand All @@ -48,7 +48,9 @@ public static void SetContainer([NotNull] this IMutableEntityType entityType, [C
/// <param name="name"> The name to set. </param>
/// <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, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)),
Expand All @@ -68,9 +70,9 @@ 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) =>
entityType[CosmosAnnotationNames.PropertyName] as string
?? GetDefaultContainingPropertyName(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;
Expand All @@ -92,7 +94,9 @@ public static void SetContainingPropertyName([NotNull] this IMutableEntityType e
/// <param name="name"> The name to set. </param>
/// <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, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
Check.NullButNotEmpty(name, nameof(name)),
Expand Down Expand Up @@ -132,7 +136,9 @@ public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType
/// <param name="name"> The name to set. </param>
/// <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, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PartitionKeyName,
Check.NullButNotEmpty(name, nameof(name)),
Expand Down Expand Up @@ -172,7 +178,9 @@ public static void SetETagPropertyName([NotNull] this IMutableEntityType entityT
/// <param name="name"> The name to set. </param>
/// <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, bool fromDataAnnotation = false)
[NotNull] this IConventionEntityType entityType,
[CanBeNull] string name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ETagName,
Check.NullButNotEmpty(name, nameof(name)),
Expand All @@ -188,10 +196,10 @@ public static void SetETagPropertyName(
?.GetConfigurationSource();

/// <summary>
/// Gets the <see cref="IProperty"/> on this entity that is mapped to cosmos etag, if it exists.
/// Gets the <see cref="IProperty" /> on this entity that is mapped to cosmos etag, if it exists.
/// </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>
/// <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)
{
Check.NotNull(entityType, nameof(entityType));
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanB
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
public static string SetDefaultContainer(
[NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false)
[NotNull] this IConventionModel model,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
model.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Expand Down
10 changes: 6 additions & 4 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static class CosmosPropertyExtensions
/// </summary>
/// <param name="property"> The property. </param>
/// <returns> Returns the property name that the property is mapped to when targeting Cosmos. </returns>
public static string GetJsonPropertyName([NotNull] this IProperty property) =>
(string)property[CosmosAnnotationNames.PropertyName]
?? GetDefaultJsonPropertyName(property);
public static string GetJsonPropertyName([NotNull] this IProperty property)
=> (string)property[CosmosAnnotationNames.PropertyName]
?? GetDefaultJsonPropertyName(property);

private static string GetDefaultJsonPropertyName(IProperty property)
{
Expand Down Expand Up @@ -62,7 +62,9 @@ public static void SetJsonPropertyName([NotNull] this IMutableProperty property,
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> The configured value. </returns>
public static string SetJsonPropertyName(
[NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false)
[NotNull] this IConventionProperty property,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static readonly MethodInfo WithPartitionKeyMethodInfo

/// <summary>
/// Specify the partition key for partition used for the query. Required when using
/// a resource token that provides permission based on a partition key for authentication,
/// a resource token that provides permission based on a partition key for authentication,
/// </summary>
/// <typeparam name="TEntity"> The type of entity being queried. </typeparam>
/// <param name="source"> The source query. </param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public virtual CosmosDbContextOptionsBuilder Region([NotNull] string region)
/// <summary>
/// Limits the operations to the provided endpoint.
/// </summary>
/// <param name="enable"> <see langword="true"/> to limit the operations to the provided endpoint. </param>
/// <param name="enable"> <see langword="true" /> to limit the operations to the provided endpoint. </param>
public virtual CosmosDbContextOptionsBuilder LimitToEndpoint(bool enable = true)
=> WithOption(e => e.WithLimitToEndpoint(Check.NotNull(enable, nameof(enable))));

Expand Down Expand Up @@ -141,22 +141,25 @@ protected virtual CosmosDbContextOptionsBuilder WithOption([NotNull] Func<Cosmos
/// </summary>
/// <returns> A string that represents the current object. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override string ToString() => base.ToString();
public override string ToString()
=> base.ToString();

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj"> The object to compare with the current object. </param>
/// <returns> <see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>. </returns>
/// <returns> <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => base.Equals(obj);
public override bool Equals(object obj)
=> base.Equals(obj);

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns> A hash code for the current object. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => base.GetHashCode();
public override int GetHashCode()
=> base.GetHashCode();

#endregion
}
Expand Down
Loading