Skip to content

Commit

Permalink
API review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Mar 27, 2023
1 parent a1855d0 commit 4717f03
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/EFCore.Proxies/ProxiesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ public static DbContextOptionsBuilder UseLazyLoadingProxies(
/// <returns>The same builder to allow method calls to be chained.</returns>
public static DbContextOptionsBuilder UseLazyLoadingProxies(
this DbContextOptionsBuilder optionsBuilder,
Action<LazyLoadingProxiesOptionsBuilder>? lazyLoadingProxiesOptionsAction)
Action<LazyLoadingProxiesOptionsBuilder> lazyLoadingProxiesOptionsAction)
{
Check.NotNull(lazyLoadingProxiesOptionsAction, nameof(lazyLoadingProxiesOptionsAction));

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

((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(
extension.WithLazyLoading(useLazyLoadingProxies: true));

lazyLoadingProxiesOptionsAction?.Invoke(new LazyLoadingProxiesOptionsBuilder(optionsBuilder));
lazyLoadingProxiesOptionsAction.Invoke(new LazyLoadingProxiesOptionsBuilder(optionsBuilder));

return optionsBuilder;
}
Expand Down Expand Up @@ -202,7 +204,7 @@ public static DbContextOptionsBuilder<TContext> UseLazyLoadingProxies<TContext>(
/// <returns>The same builder to allow method calls to be chained.</returns>
public static DbContextOptionsBuilder<TContext> UseLazyLoadingProxies<TContext>(
this DbContextOptionsBuilder<TContext> optionsBuilder,
Action<LazyLoadingProxiesOptionsBuilder>? lazyLoadingProxiesOptionsAction)
Action<LazyLoadingProxiesOptionsBuilder> lazyLoadingProxiesOptionsAction)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseLazyLoadingProxies((DbContextOptionsBuilder)optionsBuilder, lazyLoadingProxiesOptionsAction);

Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/CollectionEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public override bool IsModified
/// </para>
/// </remarks>
/// <param name="options">Options to control the way related entities are loaded.</param>
public override void Load(LoadOptions options = LoadOptions.Default)
public override void Load(LoadOptions options = LoadOptions.None)
{
EnsureInitialized();

Expand Down Expand Up @@ -244,7 +244,7 @@ public override void Load(LoadOptions options = LoadOptions.Default)
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous save operation.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
public override Task LoadAsync(LoadOptions options = LoadOptions.Default, CancellationToken cancellationToken = default)
public override Task LoadAsync(LoadOptions options = LoadOptions.None, CancellationToken cancellationToken = default)
{
EnsureInitialized();

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/LoadOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum LoadOptions
/// Use <see cref="ForceIdentityResolution" /> to avoid getting these duplicates.
/// </para>
/// </summary>
Default = 0,
None = 0,

/// <summary>
/// <para>
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/NavigationEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static INavigationBase GetNavigation(InternalEntityEntry internalEntry,
/// </para>
/// </remarks>
/// <param name="options">Options to control the way related entities are loaded.</param>
public abstract void Load(LoadOptions options = LoadOptions.Default);
public abstract void Load(LoadOptions options = LoadOptions.None);

/// <summary>
/// Loads entities referenced by this navigation property, unless <see cref="NavigationEntry.IsLoaded" />
Expand All @@ -115,7 +115,7 @@ private static INavigationBase GetNavigation(InternalEntityEntry internalEntry,
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous save operation.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
public abstract Task LoadAsync(LoadOptions options = LoadOptions.Default, CancellationToken cancellationToken = default);
public abstract Task LoadAsync(LoadOptions options = LoadOptions.None, CancellationToken cancellationToken = default);

/// <summary>
/// Returns the query that would be used by <see cref="Load" /> to load entities referenced by
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/ReferenceEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void LocalDetectChanges()
/// </para>
/// </remarks>
/// <param name="options">Options to control the way related entities are loaded.</param>
public override void Load(LoadOptions options = LoadOptions.Default)
public override void Load(LoadOptions options = LoadOptions.None)
{
if (!IsLoaded)
{
Expand All @@ -112,7 +112,7 @@ public override void Load(LoadOptions options = LoadOptions.Default)
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous save operation.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
public override Task LoadAsync(LoadOptions options = LoadOptions.Default, CancellationToken cancellationToken = default)
public override Task LoadAsync(LoadOptions options = LoadOptions.None, CancellationToken cancellationToken = default)
=> IsLoaded
? Task.CompletedTask
: TargetFinder.LoadAsync((INavigation)Metadata, InternalEntry, options, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Infrastructure/Internal/LazyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public virtual void Load(object entity, [CallerMemberName] string navigationName
entry.Load(
_queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
? LoadOptions.ForceIdentityResolution
: LoadOptions.Default);
: LoadOptions.None);
}
catch
{
Expand Down Expand Up @@ -161,7 +161,7 @@ public virtual async Task LoadAsync(
await entry.LoadAsync(
_queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
? LoadOptions.ForceIdentityResolution
: LoadOptions.Default,
: LoadOptions.None,
cancellationToken).ConfigureAwait(false);
}
catch
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Internal/EntityFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public virtual IQueryable<TEntity> Query(INavigation navigation, InternalEntityE
return _queryRoot.Where(e => false);
}

return Query(navigation, keyValues, entry, LoadOptions.Default);
return Query(navigation, keyValues, entry, LoadOptions.None);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Internal/ManyToManyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public virtual IQueryable<TEntity> Query(InternalEntityEntry entry)
return queryRoot.Where(e => false);
}

return Query(context, keyValues, entry, LoadOptions.Default);
return Query(context, keyValues, entry, LoadOptions.None);
}

private object[]? PrepareForLoad(InternalEntityEntry entry)
Expand Down
10 changes: 5 additions & 5 deletions test/EFCore.Specification.Tests/ManyToManyLoadTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ public virtual async Task Load_collection_partially_loaded(EntityState state, bo
{
if (async)
{
await collectionEntry.LoadAsync(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.Default);
await collectionEntry.LoadAsync(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.None);
}
else
{
collectionEntry.Load(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.Default);
collectionEntry.Load(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.None);
}

Assert.True(collectionEntry.IsLoaded);
Expand Down Expand Up @@ -519,11 +519,11 @@ public virtual async Task Load_collection_partially_loaded_no_explicit_join(Enti
{
if (async)
{
await collectionEntry.LoadAsync(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.Default);
await collectionEntry.LoadAsync(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.None);
}
else
{
collectionEntry.Load(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.Default);
collectionEntry.Load(forceIdentityResolution ? LoadOptions.ForceIdentityResolution : LoadOptions.None);
}

Assert.True(collectionEntry.IsLoaded);
Expand Down Expand Up @@ -575,7 +575,7 @@ public virtual void Load_collection_partially_loaded_no_tracking(QueryTrackingBe
collectionEntry.Load(
queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
? LoadOptions.ForceIdentityResolution
: LoadOptions.Default);
: LoadOptions.None);
}

context.ChangeTracker.LazyLoadingEnabled = false;
Expand Down

0 comments on commit 4717f03

Please sign in to comment.