public CompiledQueryCacheKey(
     [NotNull] string query,
     [NotNull] IModel model,
     QueryTrackingBehavior queryTrackingBehavior,
     bool async)
 {
     _query = query;
     _model = model;
     _queryTrackingBehavior = queryTrackingBehavior;
     _async = async;
 }
Ejemplo n.º 2
0
 public BaseContext(DbContextOptions options, QueryTrackingBehavior queryTrackingBehaviour = QueryTrackingBehavior.NoTracking) : base(options)
 {
     ChangeTracker.QueryTrackingBehavior = queryTrackingBehaviour;
 }
 public override NorthwindContext CreateContext(
     QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll)
 => new NorthwindContext(BuildOptions(), queryTrackingBehavior);
 public void WithTrackingBehavior(QueryTrackingBehavior trackingBehavior)
 {
     ChangeTracker.QueryTrackingBehavior = trackingBehavior;
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     <para>
 ///         Sets the tracking behavior for LINQ queries run against the context. Disabling change tracking
 ///         is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each
 ///         entity instance. You should not disable change tracking if you want to manipulate entity instances and
 ///         persist those changes to the database using <see cref="DbContext.SaveChanges()" />.
 ///     </para>
 ///     <para>
 ///         This method sets the default behavior for all contexts created with these options, but you can override this
 ///         behavior for a context instance using <see cref="ChangeTracker.QueryTrackingBehavior" /> or on individual
 ///         queries using the <see cref="EntityFrameworkQueryableExtensions.AsNoTracking{TEntity}(IQueryable{TEntity})" />
 ///         and <see cref="EntityFrameworkQueryableExtensions.AsTracking{TEntity}(IQueryable{TEntity})" /> methods.
 ///     </para>
 ///     <para>
 ///         The default value is <see cref="EntityFrameworkCore.QueryTrackingBehavior.TrackAll" />. This means the change tracker will
 ///         keep track of changes for all entities that are returned from a LINQ query.
 ///     </para>
 /// </summary>
 public virtual DbContextOptionsBuilder UseQueryTrackingBehavior(QueryTrackingBehavior queryTrackingBehavior)
 => SetOption(e => e.QueryTrackingBehavior = queryTrackingBehavior);
 /// <summary>
 ///     <para>
 ///         Sets the tracking behavior for LINQ queries run against the context. Disabling change tracking
 ///         is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each
 ///         entity instance. You should not disable change tracking if you want to manipulate entity instances and
 ///         persist those changes to the database using <see cref="DbContext.SaveChanges()" />.
 ///     </para>
 ///     <para>
 ///         This method sets the default behavior for all contexts created with these options, but you can override this
 ///         behavior for a context instance using <see cref="ChangeTracker.QueryTrackingBehavior" /> or on individual
 ///         queries using the <see cref="EntityFrameworkQueryableExtensions.AsNoTracking{TEntity}(IQueryable{TEntity})" />
 ///         and <see cref="EntityFrameworkQueryableExtensions.AsTracking{TEntity}(IQueryable{TEntity})" /> methods.
 ///     </para>
 ///     <para>
 ///         The default value is <see cref="EntityFrameworkCore.QueryTrackingBehavior.TrackAll" />. This means
 ///         the change tracker will keep track of changes for all entities that are returned from a LINQ query.
 ///     </para>
 /// </summary>
 /// <returns> The same builder instance so that multiple calls can be chained. </returns>
 public virtual DbContextOptionsBuilder UseQueryTrackingBehavior(QueryTrackingBehavior queryTrackingBehavior)
 => WithOption(e => e.WithQueryTrackingBehavior(queryTrackingBehavior));
Ejemplo n.º 7
0
 /// <summary>
 ///     <para>
 ///         Sets the tracking behavior for LINQ queries run against the context. Disabling change tracking
 ///         is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each
 ///         entity instance. You should not disable change tracking if you want to manipulate entity instances and
 ///         persist those changes to the database using <see cref="DbContext.SaveChanges()" />.
 ///     </para>
 ///     <para>
 ///         This method sets the default behavior for all contexts created with these options, but you can override this
 ///         behavior for a context instance using <see cref="ChangeTracker.QueryTrackingBehavior" /> or on individual
 ///         queries using the <see cref="EntityFrameworkQueryableExtensions.AsNoTracking{TEntity}(IQueryable{TEntity})" />
 ///         and <see cref="EntityFrameworkQueryableExtensions.AsTracking{TEntity}(IQueryable{TEntity})" /> methods.
 ///     </para>
 ///     <para>
 ///         The default value is <see cref="EntityFrameworkCore.QueryTrackingBehavior.TrackAll" />. This means the
 ///         change tracker will keep track of changes for all entities that are returned from a LINQ query.
 ///     </para>
 /// </summary>
 public new virtual DbContextOptionsBuilder <TContext> UseQueryTrackingBehavior(QueryTrackingBehavior queryTrackingBehavior)
 => (DbContextOptionsBuilder <TContext>)base.UseQueryTrackingBehavior(queryTrackingBehavior);
Ejemplo n.º 8
0
 public override NorthwindContext CreateContext(
     QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll)
 => new SqlServerNorthwindContext(_options, queryTrackingBehavior);
Ejemplo n.º 9
0
 public SqlServerNorthwindContext(DbContextOptions options,
                                  QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll)
     : base(options, queryTrackingBehavior)
 {
 }
 public IQueryable <TEntidade> ListarOrdenadosPor <TKey>(Expression <Func <TEntidade, TKey> > ordem, bool ascendente = true, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll, params string[] includeProperties)
 {
     return(ascendente ? Listar(queryTrackingBehavior, includeProperties).OrderBy(ordem) : Listar(queryTrackingBehavior, includeProperties).OrderByDescending(ordem));
 }
 public TEntidade ObterPor(Func <TEntidade, bool> where, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll)
 {
     return(Listar(queryTrackingBehavior).FirstOrDefault(where));
 }
 public TEntidade ObterPor(Func <TEntidade, bool> where, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll, params string[] includeProperties)
 {
     return(Listar(queryTrackingBehavior, includeProperties).FirstOrDefault(where));
 }
 public IQueryable <TEntidade> ListarPor(Expression <Func <TEntidade, bool> > where, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll, params string[] includeProperties)
 {
     return(Listar(queryTrackingBehavior, includeProperties).Where(where));
 }
 public IQueryable <TEntidade> ListarPor(Expression <Func <TEntidade, bool> > where, QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll)
 {
     return(Listar(queryTrackingBehavior).Where(where));
 }
 public abstract NorthwindContext CreateContext(
     QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll);
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrototypeContext" /> class.
 /// </summary>
 /// <param name="applicationConfiguration">
 /// Configuration information for the application.
 /// </param>
 /// <param name="databaseType">
 /// The database type of the backing database. The default value is <see cref="ContextDatabaseType.SQLServer" />.
 /// </param>
 /// <param name="trackingBehavior">
 /// The query result tracking behavior for the context. The default value is <see cref="QueryTrackingBehavior.TrackAll" />.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="applicationConfiguration" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="databaseType" /> is equal to <see cref="ContextDatabaseType.Unspecified" />.
 /// </exception>
 public PrototypeContext(IConfiguration applicationConfiguration, ContextDatabaseType databaseType, QueryTrackingBehavior trackingBehavior)
     : base(applicationConfiguration, databaseType, trackingBehavior)
 {
     return;
 }
Ejemplo n.º 17
0
 public AppDatabaseContext(QueryTrackingBehavior changeTrackingBehavior)
 {
     ChangeTracker.QueryTrackingBehavior = changeTrackingBehavior;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a scope in which a DbContext instance behaves differently.
        /// The behaviour is resetted on disposal of the scope to what it was before.
        /// </summary>
        /// <param name="ctx">The context instance to change behavior for.</param>
        /// <param name="deferCommit">
        /// Suppresses the execution of <see cref="DbContext.SaveChanges()"/> / <see cref="DbContext.SaveChangesAsync(CancellationToken)"/>
        /// until this instance is disposed or <see cref="Commit()"/> / <see cref="CommitAsync(CancellationToken)"/> is called explicitly.
        /// </param>
        /// <param name="retainConnection">
        /// Opens connection and retains it until disposal. May increase load/save performance in large scopes.
        /// </param>
        public DbContextScope(HookingDbContext ctx,
                              bool?autoDetectChanges            = null,
                              bool?lazyLoading                  = null,
                              bool?forceNoTracking              = null,
                              bool?deferCommit                  = false,
                              bool retainConnection             = false,
                              HookImportance?minHookImportance  = null,
                              CascadeTiming?cascadeDeleteTiming = null,
                              CascadeTiming?deleteOrphansTiming = null,
                              bool?autoTransactions             = null)
        {
            Guard.NotNull(ctx, nameof(ctx));

            var changeTracker = ctx.ChangeTracker;

            _ctx = ctx;
            _autoDetectChangesEnabled = changeTracker.AutoDetectChangesEnabled;
            _minHookImportance        = ctx.MinHookImportance;
            _suppressCommit           = ctx.SuppressCommit;
            _lazyLoadingEnabled       = changeTracker.LazyLoadingEnabled;
            _queryTrackingBehavior    = changeTracker.QueryTrackingBehavior;
            _cascadeDeleteTiming      = changeTracker.CascadeDeleteTiming;
            _deleteOrphansTiming      = changeTracker.DeleteOrphansTiming;
            _autoTransactionEnabled   = ctx.Database.AutoTransactionsEnabled;
            _retainConnection         = retainConnection;

            if (autoDetectChanges.HasValue)
            {
                changeTracker.AutoDetectChangesEnabled = autoDetectChanges.Value;
            }

            if (minHookImportance.HasValue)
            {
                ctx.MinHookImportance = minHookImportance.Value;
            }

            if (lazyLoading.HasValue)
            {
                changeTracker.LazyLoadingEnabled = lazyLoading.Value;
            }

            if (forceNoTracking == true)
            {
                changeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            }

            if (deferCommit.HasValue)
            {
                ctx.SuppressCommit = deferCommit.Value;
            }

            if (cascadeDeleteTiming.HasValue)
            {
                changeTracker.CascadeDeleteTiming = cascadeDeleteTiming.Value;
            }

            if (deleteOrphansTiming.HasValue)
            {
                changeTracker.DeleteOrphansTiming = deleteOrphansTiming.Value;
            }

            if (autoTransactions.HasValue)
            {
                ctx.Database.AutoTransactionsEnabled = autoTransactions.Value;
            }

            if (retainConnection)
            {
                ctx.Database.OpenConnection();
            }
        }