Skip to content

Commit

Permalink
More nullability annotations
Browse files Browse the repository at this point in the history
Update pipeline, value generation, and many additional bits and pieces.
  • Loading branch information
roji committed Mar 2, 2021
1 parent c65e02d commit d116dcf
Show file tree
Hide file tree
Showing 134 changed files with 825 additions and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static string ExecutingSqlQuery(EventDefinitionBase definition, EventDat
public static void ExecutingReadItem(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Database.Command> diagnostics,
[NotNull] string containerId,
[CanBeNull] string partitionKey,
[CanBeNull] string? partitionKey,
[NotNull] string resourceId)
{
var definition = CosmosResources.LogExecutingReadItem(diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -55,8 +57,6 @@ private static TService GetService<TService>(IInfrastructure<IServiceProvider> d
/// <param name="database"> The facade from <see cref="DbContext.Database" />. </param>
/// <returns> <see langword="true" /> if the Cosmos provider is being used. </returns>
public static bool IsCosmos([NotNull] this DatabaseFacade database)
=> database.ProviderName.Equals(
typeof(CosmosOptionsExtension).Assembly.GetName().Name,
StringComparison.Ordinal);
=> database.ProviderName == typeof(CosmosOptionsExtension).Assembly.GetName().Name;
}
}
10 changes: 6 additions & 4 deletions src/EFCore.Cosmos/Extensions/CosmosDbContextOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -30,7 +32,7 @@ public static DbContextOptionsBuilder<TContext> UseCosmos<TContext>(
[NotNull] string accountEndpoint,
[NotNull] string accountKey,
[NotNull] string databaseName,
[CanBeNull] Action<CosmosDbContextOptionsBuilder> cosmosOptionsAction = null)
[CanBeNull] Action<CosmosDbContextOptionsBuilder>? cosmosOptionsAction = null)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseCosmos(
(DbContextOptionsBuilder)optionsBuilder,
Expand All @@ -53,7 +55,7 @@ public static DbContextOptionsBuilder UseCosmos(
[NotNull] string accountEndpoint,
[NotNull] string accountKey,
[NotNull] string databaseName,
[CanBeNull] Action<CosmosDbContextOptionsBuilder> cosmosOptionsAction = null)
[CanBeNull] Action<CosmosDbContextOptionsBuilder>? cosmosOptionsAction = null)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));
Check.NotNull(accountEndpoint, nameof(accountEndpoint));
Expand Down Expand Up @@ -88,7 +90,7 @@ public static DbContextOptionsBuilder<TContext> UseCosmos<TContext>(
[NotNull] this DbContextOptionsBuilder<TContext> optionsBuilder,
[NotNull] string connectionString,
[NotNull] string databaseName,
[CanBeNull] Action<CosmosDbContextOptionsBuilder> cosmosOptionsAction = null)
[CanBeNull] Action<CosmosDbContextOptionsBuilder>? cosmosOptionsAction = null)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseCosmos(
(DbContextOptionsBuilder)optionsBuilder,
Expand All @@ -108,7 +110,7 @@ public static DbContextOptionsBuilder UseCosmos(
[NotNull] this DbContextOptionsBuilder optionsBuilder,
[NotNull] string connectionString,
[NotNull] string databaseName,
[CanBeNull] Action<CosmosDbContextOptionsBuilder> cosmosOptionsAction = null)
[CanBeNull] Action<CosmosDbContextOptionsBuilder>? cosmosOptionsAction = null)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));
Check.NotNull(connectionString, nameof(connectionString));
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public static void SetContainer(
?? GetDefaultContainingPropertyName(entityType);

private static string? GetDefaultContainingPropertyName(IReadOnlyEntityType entityType)
=> entityType.FindOwnership()?.PrincipalToDependent!.Name;
=> entityType.FindOwnership() is IReadOnlyForeignKey ownership
? ownership.PrincipalToDependent!.Name
: null;

/// <summary>
/// Sets the name of the parent property to which the entity type is mapped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.EntityFrameworkCore.ValueGeneration;

#nullable enable

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -63,7 +65,7 @@ public static IServiceCollection AddEntityFrameworkCosmos([NotNull] this IServic
// New Query pipeline
.TryAdd<IQueryableMethodTranslatingExpressionVisitorFactory, CosmosQueryableMethodTranslatingExpressionVisitorFactory>()
.TryAdd<IShapedQueryCompilingExpressionVisitorFactory, CosmosShapedQueryCompilingExpressionVisitorFactory>()
.TryAdd<ISingletonOptions, ICosmosSingletonOptions>(p => p.GetService<ICosmosSingletonOptions>())
.TryAdd<ISingletonOptions, ICosmosSingletonOptions>(p => p.GetRequiredService<ICosmosSingletonOptions>())
.TryAdd<IQueryTranslationPreprocessorFactory, CosmosQueryTranslationPreprocessorFactory>()
.TryAdd<IQueryCompilationContextFactory, CosmosQueryCompilationContextFactory>()
.TryAdd<IQueryTranslationPostprocessorFactory, CosmosQueryTranslationPostprocessorFactory>()
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.Cosmos/Storage/Internal/ByteArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using Newtonsoft.Json;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal
{
/// <summary>
Expand All @@ -23,7 +25,7 @@ public class ByteArrayConverter : JsonConverter
/// </summary>
public override void WriteJson(
JsonWriter writer,
object value,
object? value,
JsonSerializer serializer)
{
if (value == null)
Expand Down
Loading

0 comments on commit d116dcf

Please sign in to comment.