Skip to content

Commit

Permalink
Update API docs
Browse files Browse the repository at this point in the history
* Document connection obtained from DatabaseFacade.GetDbConnection() should normally not be disposed Fixes #11415
* Add XML docs referencing how to determine the default CommandTimeout Fixes #17503
* Clarify behavior for EnsureExists with an empty database Fixes #17563
* A hyperlink to the DbContext.Database.Migrate() method would be useful Fixes #17571
* Default values for maxRetryCount, maxRetryDelay, and errorNumbersToAdd Fixes #17574
* Document that modifying entity states while iterating over entries can result in "Collection was modified" exception Fixes #18389
* Update API doc links to correctly reference external dependencies Fixes #18580
* Make it clearer how to access EF.Functions Fixes #21424
* Improve API docs for TrackGraph Fixes #22529
  • Loading branch information
ajcvickers committed Sep 20, 2020
1 parent 3199752 commit d18cb89
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,15 @@ public static async Task<int> ExecuteSqlRawAsync(
}

/// <summary>
/// Gets the underlying ADO.NET <see cref="DbConnection" /> for this <see cref="DbContext" />.
/// <para>
/// Gets the underlying ADO.NET <see cref="DbConnection" /> for this <see cref="DbContext" />.
/// </para>
/// <para>
/// This connection should not be disposed if it was created by Entity Framework. Connections are created by
/// Entity Framework when a connection string rather than a DbConnection object is passed to the the 'UseMyProvider'
/// method for the database provider in use. Conversely, the application is responsible for disposing a DbConnection
/// passed to Entity Framework in 'UseMtyProvider'.
/// </para>
/// </summary>
/// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
/// <returns> The <see cref="DbConnection" /> </returns>
Expand Down Expand Up @@ -605,8 +613,19 @@ public static Task<IDbContextTransaction> UseTransactionAsync(
/// Sets the timeout (in seconds) to use for commands executed with this <see cref="DbContext" />.
/// </para>
/// <para>
/// Note that the command timeout is distinct from the connection timeout, which is commonly
/// set on the database connection string.
/// If this value is set, then it is used to set <see cref="DbCommand.CommandTimeout" /> whenever Entity Framework creates a
/// <see cref="DbCommand" /> to execute a query.
/// </para>
/// <para>
/// If this value is not set, then the default value used is defined by the underlying ADO.NET data provider.
/// Consult the documentation for the implementation of <see cref="DbCommand" /> in the ADO.NET data provider for details of
/// default values, etc.
/// </para>
/// <para>
/// Note that the command timeout is distinct from the connection timeout. Connection timeouts are usually
/// configured in the connection string. More recently, some ADO.NET data providers are adding the capability
/// to also set a command timeout in the connection string. A value set with this API for the command timeout
/// will override any value set in the connection string.
/// </para>
/// </summary>
/// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
Expand All @@ -619,8 +638,8 @@ public static void SetCommandTimeout([NotNull] this DatabaseFacade databaseFacad
/// Sets the timeout to use for commands executed with this <see cref="DbContext" />.
/// </para>
/// <para>
/// Note that the command timeout is distinct from the connection timeout, which is commonly
/// set on the database connection string.
/// This is a sugar method allowing a <see cref="TimeSpan" /> to be used to set the value. It delegates to
/// <see cref="SetCommandTimeout(DatabaseFacade,Nullable{int})" />.
/// </para>
/// </summary>
/// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure
/// Allows SQL Server specific configuration to be performed on <see cref="DbContextOptions" />.
/// </para>
/// <para>
/// Instances of this class are returned from a call to
/// <see
/// cref="SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder,string,System.Action{Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder})" />
/// Instances of this class are returned from a call to <see cref="M:SqlServerDbContextOptionsExtensions.UseSqlServer" />
/// and it is not designed to be directly constructed in your application code.
/// </para>
/// </summary>
Expand All @@ -33,19 +31,43 @@ public SqlServerDbContextOptionsBuilder([NotNull] DbContextOptionsBuilder option
}

/// <summary>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// <para>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// </para>
/// <para>
/// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with
/// error numbers for transient errors that can be retried.
/// </para>
/// <para>
/// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used.
/// </para>
/// </summary>
public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure()
=> ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c));

/// <summary>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// <para>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// </para>
/// <para>
/// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with
/// error numbers for transient errors that can be retried.
/// </para>
/// <para>
/// A default value 30 seconds for the maximum default delay is used.
/// </para>
/// </summary>
public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure(int maxRetryCount)
=> ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c, maxRetryCount));

/// <summary>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// <para>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// </para>
/// <para>
/// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with
/// error numbers for transient errors that can be retried, but additional error numbers can also be supplied.
/// </para>
/// </summary>
/// <param name="maxRetryCount"> The maximum number of retry attempts. </param>
/// <param name="maxRetryDelay"> The maximum delay between retries. </param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public override IReadOnlyList<MigrationCommand> Generate(
/// <see cref="MigrationCommandListBuilder" />.
/// </para>
/// <para>
/// This method uses a double-dispatch mechanism to call one of the 'Generate' methods that are
/// specific to a certain subtype of <see cref="MigrationOperation" />. Typically database providers
/// This method uses a double-dispatch mechanism to call one of the <see cref="M:MigrationsSqlGenerator.Generate" /> methods
/// that are specific to a certain subtype of <see cref="MigrationOperation" />. Typically database providers
/// will override these specific methods rather than this method. However, providers can override
/// this methods to handle provider-specific operations.
/// </para>
Expand Down
40 changes: 31 additions & 9 deletions src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// An <see cref="IExecutionStrategy" /> implementation for retrying failed executions
/// on SQL Server.
/// <para>
/// An <see cref="IExecutionStrategy" /> implementation for retrying failed executions on SQL Server.
/// </para>
/// <para>
/// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with
/// error numbers for transient errors that can be retried. Additional error numbers to retry on can also be supplied.
/// </para>
/// </summary>
public class SqlServerRetryingExecutionStrategy : ExecutionStrategy
{
private readonly ICollection<int> _additionalErrorNumbers;

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// <para>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </para>
/// <para>
/// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used.
/// </para>
/// </summary>
/// <param name="context"> The context on which the operations will be invoked. </param>
/// <remarks>
/// The default retry limit is 6, which means that the total amount of time spent before failing is about a minute.
/// </remarks>
public SqlServerRetryingExecutionStrategy(
[NotNull] DbContext context)
: this(context, DefaultMaxRetryCount)
{
}

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// <para>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </para>
/// <para>
/// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used.
/// </para>
/// </summary>
/// <param name="dependencies"> Parameter object containing service dependencies. </param>
public SqlServerRetryingExecutionStrategy(
Expand All @@ -43,7 +55,12 @@ public SqlServerRetryingExecutionStrategy(
}

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// <para>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </para>
/// <para>
/// A default value 30 seconds for the maximum default delay is used.
/// </para>
/// </summary>
/// <param name="context"> The context on which the operations will be invoked. </param>
/// <param name="maxRetryCount"> The maximum number of retry attempts. </param>
Expand All @@ -55,7 +72,12 @@ public SqlServerRetryingExecutionStrategy(
}

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// <para>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </para>
/// <para>
/// A default value 30 seconds for the maximum default delay is used.
/// </para>
/// </summary>
/// <param name="dependencies"> Parameter object containing service dependencies. </param>
/// <param name="maxRetryCount"> The maximum number of retry attempts. </param>
Expand Down
15 changes: 13 additions & 2 deletions src/EFCore/ChangeTracking/ChangeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,19 @@ public virtual CascadeTiming CascadeDeleteTiming
}

/// <summary>
/// Gets an <see cref="EntityEntry" /> for each entity being tracked by the context.
/// The entries provide access to change tracking information and operations for each entity.
/// <para>
/// Returns an <see cref="EntityEntry" /> for each entity being tracked by the context.
/// The entries provide access to change tracking information and operations for each entity.
/// </para>
/// <para>
/// This method calls <see cref="DetectChanges" /> to ensure all entries returned reflect up-to-date state.
/// Use <see cref="AutoDetectChangesEnabled" /> to prevent DetectChanges from being called automatically.
/// </para>
/// <para>
/// Note that modification of entity state while iterating over the returned enumeration may result in
/// an <see cref="InvalidOperationException" /> indicating that the collection was modified while enumerating.
/// To avoid this, create a defensive copy using <see cref="Enumerable.ToList{TSource}" /> or similar before iterating.
/// </para>
/// </summary>
/// <returns> An entry for each entity being tracked. </returns>
public virtual IEnumerable<EntityEntry> Entries()
Expand Down
32 changes: 27 additions & 5 deletions src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
namespace Microsoft.EntityFrameworkCore.ChangeTracking
{
/// <summary>
/// Provides access to change tracking information and operations for a node in a
/// graph of entities that is being traversed.
/// <para>
/// Provides access to change tracking information and operations for a node in a
/// graph of entities that is being traversed.
/// </para>
/// <para>
/// See <see cref="M:ChangeTracker.TrackGraph" /> for information on how graph nodes are used.
/// </para>
/// </summary>
public class EntityEntryGraphNode : IInfrastructure<InternalEntityEntry>
{
Expand Down Expand Up @@ -40,18 +45,34 @@ public EntityEntryGraphNode(
}

/// <summary>
/// Gets the entry tracking information about this entity.
/// <para>
/// An <see cref="EntityEntry" /> for the entity instance from which a navigation property was traversed to the the instance
/// represented by this node.
/// </para>
/// <para>
/// See <see cref="M:ChangeTracker.TrackGraph" /> for information on how graph nodes are used.
/// </para>
/// </summary>
public virtual EntityEntry SourceEntry
=> _sourceEntry == null ? null : new EntityEntry(_sourceEntry);

/// <summary>
/// Gets the navigation property that is being traversed to reach this node in the graph.
/// <para>
/// Gets the navigation property that is being traversed to reach this node in the graph.
/// </para>
/// <para>
/// See <see cref="M:ChangeTracker.TrackGraph" /> for information on how graph nodes are used.
/// </para>
/// </summary>
public virtual INavigationBase InboundNavigation { get; }

/// <summary>
/// Gets the entry tracking information about this entity.
/// <para>
/// An <see cref="EntityEntry" /> for the entity instance represented by this node.
/// </para>
/// <para>
/// See <see cref="M:ChangeTracker.TrackGraph" /> for information on how graph nodes are used.
/// </para>
/// </summary>
public virtual EntityEntry Entry
=> new EntityEntry(_entry);
Expand All @@ -65,6 +86,7 @@ public virtual EntityEntry Entry
/// application code.
/// </para>
/// </summary>
[EntityFrameworkInternal]
InternalEntityEntry IInfrastructure<InternalEntityEntry>.Instance
=> _entry;

Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/DbContextOptionsBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public DbContextOptionsBuilder([NotNull] DbContextOptions<TContext> options)
/// for logging done by this context.
/// </para>
/// <para>
/// There is no need to call this method when using one of the 'AddDbContext' methods.
/// 'AddDbContext' will ensure that the <see cref="ILoggerFactory" /> used by EF is obtained from the
/// There is no need to call this method when using one of the <see cref="M:EntityFrameworkServiceCollectionExtensions.AddDbContext" />
/// methods. 'AddDbContext' will ensure that the <see cref="ILoggerFactory" /> used by EF is obtained from the
/// application service provider.
/// </para>
/// <para>
Expand Down
4 changes: 4 additions & 0 deletions src/EFCore/DbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public virtual IQueryable<TEntity> AsQueryable()
/// <see cref="LocalView{TEntity}.ToObservableCollection" /> for WPF binding, or
/// <see cref="LocalView{TEntity}.ToBindingList" /> for WinForms.
/// </para>
/// <para>
/// Note that this method calls <see cref="ChangeTracker.DetectChanges" /> unless
/// <see cref="ChangeTracker.AutoDetectChangesEnabled" /> has been set to <see langword="false" />.
/// </para>
/// </summary>
public virtual LocalView<TEntity> Local
=> throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Diagnostics/InterceptionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// <para>
/// Represents a result from an <see cref="IInterceptor" /> such as an 'IDbConnectionInterceptor' to allow
/// Represents a result from an <see cref="IInterceptor" /> such as an <see cref="ISaveChangesInterceptor" /> to allow
/// suppression of the normal operation being intercepted.
/// </para>
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Diagnostics/InterceptionResult`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// <para>
/// Represents a result from an <see cref="IInterceptor" /> such as an 'IDbCommandInterceptor' to allow
/// Represents a result from an <see cref="IInterceptor" /> such as an <see cref="ISaveChangesInterceptor" /> to allow
/// suppression of the normal operation being intercepted.
/// </para>
/// <para>
Expand Down
Loading

0 comments on commit d18cb89

Please sign in to comment.