Пример #1
0
            public override DbUpdateException Optional_many_to_one_dependents_are_orphaned_starting_detached(
                CascadeTiming?cascadeDeleteTiming,
                CascadeTiming?deleteOrphansTiming)
            {
                var updateException = base.Optional_many_to_one_dependents_are_orphaned_starting_detached(
                    cascadeDeleteTiming,
                    deleteOrphansTiming);

                // Disabled check -- see issue #11031
                //Assert.Contains("FK_Optional2_Optional1_ParentId", updateException.InnerException.Message);

                return(updateException);
            }
Пример #2
0
            public override DbUpdateException Required_many_to_one_dependents_with_alternate_key_are_cascade_deleted_in_store(
                CascadeTiming?cascadeDeleteTiming,
                CascadeTiming?deleteOrphansTiming)
            {
                var updateException = base.Required_many_to_one_dependents_with_alternate_key_are_cascade_deleted_in_store(
                    cascadeDeleteTiming,
                    deleteOrphansTiming);

                // Disabled check -- see issue #11031
                //Assert.Contains("FK_RequiredAk2_RequiredAk1_ParentId", updateException.InnerException.Message);

                return(updateException);
            }
Пример #3
0
            public override DbUpdateException Optional_one_to_one_with_alternate_key_are_orphaned_in_store(
                CascadeTiming?cascadeDeleteTiming,
                CascadeTiming?deleteOrphansTiming)
            {
                var updateException = base.Optional_one_to_one_with_alternate_key_are_orphaned_in_store(
                    cascadeDeleteTiming,
                    deleteOrphansTiming);

                // Disabled check -- see issue #11031
                //Assert.Contains("FK_OptionalSingleAk2_OptionalSingleAk1_BackId", updateException.InnerException.Message);

                return(updateException);
            }
Пример #4
0
            public override DbUpdateException Required_non_PK_one_to_one_are_cascade_deleted_in_store(
                CascadeTiming?cascadeDeleteTiming,
                CascadeTiming?deleteOrphansTiming)
            {
                var updateException = base.Required_non_PK_one_to_one_are_cascade_deleted_in_store(
                    cascadeDeleteTiming,
                    deleteOrphansTiming);

                // Disabled check -- see issue #11031
                //Assert.Contains("FK_RequiredNonPkSingle2_RequiredNonPkSingle1_BackId", updateException.InnerException.Message);

                return(updateException);
            }
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public DbContextPoolConfigurationSnapshot(
     bool?autoDetectChangesEnabled,
     QueryTrackingBehavior?queryTrackingBehavior,
     bool?autoTransactionsEnabled,
     bool?lazyLoadingEnabled,
     CascadeTiming?cascadeDeleteTiming,
     CascadeTiming?deleteOrphansTiming)
 {
     AutoDetectChangesEnabled = autoDetectChangesEnabled;
     QueryTrackingBehavior    = queryTrackingBehavior;
     AutoTransactionsEnabled  = autoTransactionsEnabled;
     LazyLoadingEnabled       = lazyLoadingEnabled;
     CascadeDeleteTiming      = cascadeDeleteTiming;
     DeleteOrphansTiming      = deleteOrphansTiming;
 }
Пример #6
0
 public override void Optional_one_to_one_relationships_are_one_to_one(
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #7
0
 public override void Optional_many_to_one_dependents_are_orphaned_in_store(
     CascadeTiming?cascadeDeleteTiming,
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #8
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?hooksEnabled                 = null,
                              bool?lazyLoading                  = null,
                              bool?forceNoTracking              = null,
                              bool?deferCommit                  = false,
                              bool retainConnection             = false,
                              CascadeTiming?cascadeDeleteTiming = null,
                              CascadeTiming?deleteOrphansTiming = null,
                              bool?autoTransactions             = null)
        {
            Guard.NotNull(ctx, nameof(ctx));

            var changeTracker = ctx.ChangeTracker;

            _ctx = ctx;
            _autoDetectChangesEnabled = changeTracker.AutoDetectChangesEnabled;
            _hooksEnabled             = ctx.HooksEnabled;
            _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 (hooksEnabled.HasValue)
            {
                ctx.HooksEnabled = hooksEnabled.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();
            }
        }
Пример #9
0
 public override void Sever_required_one_to_one(
     ChangeMechanism changeMechanism,
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #10
0
 public override void Required_non_PK_one_to_one_with_alternate_key_are_cascade_deleted_in_store(
     CascadeTiming?cascadeDeleteTiming,
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #11
0
 public override void Required_non_PK_one_to_one_are_cascade_detached_when_Added(
     CascadeTiming?cascadeDeleteTiming,
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #12
0
 public override void Required_One_to_one_with_AK_relationships_are_one_to_one(
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #13
0
 public override void Required_one_to_one_with_AK_relationships_are_one_to_one(CascadeTiming?deleteOrphansTiming)
 {
 }
Пример #14
0
 public override void Optional_one_to_one_with_alternate_key_are_orphaned_in_store(
     CascadeTiming?cascadeDeleteTiming,
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
 }
Пример #15
0
 public override void Sever_required_non_PK_one_to_one(
     ChangeMechanism changeMechanism,
     CascadeTiming?deleteOrphansTiming)
 {
     // Cascade delete not supported by in-memory database
 }
Пример #16
0
 public override void Required_one_to_one_with_alternate_key_are_cascade_deleted_in_store(
     CascadeTiming?cascadeDeleteTiming, CascadeTiming?deleteOrphansTiming)
 {
 }
        public virtual void New_FK_is_not_cleared_on_old_dependent_delete(
            bool loadNewParent,
            CascadeTiming?deleteOrphansTiming)
        {
            var removedId = 0;
            var childId   = 0;
            int?newFk     = 0;

            ExecuteWithStrategyInTransaction(
                context =>
            {
                context.ChangeTracker.DeleteOrphansTiming = deleteOrphansTiming ?? CascadeTiming.Never;

                var removed = context.Set <Optional1>().OrderBy(e => e.Id).First();
                var child   = context.Set <Optional2>().OrderBy(e => e.Id).First(e => e.ParentId == removed.Id);

                removedId = removed.Id;
                childId   = child.Id;

                newFk = context.Set <Optional1>().AsNoTracking().Single(e => e.Id != removed.Id).Id;

                var newParent = loadNewParent ? context.Set <Optional1>().Find(newFk) : null;

                child.ParentId = newFk;

                context.Remove(removed);

                Assert.True(context.ChangeTracker.HasChanges());

                if (Fixture.ForceClientNoAction)
                {
                    Assert.Throws <DbUpdateException>(() => context.SaveChanges());
                }
                else
                {
                    context.SaveChanges();

                    Assert.False(context.ChangeTracker.HasChanges());

                    Assert.Equal(EntityState.Detached, context.Entry(removed).State);
                    Assert.Equal(newFk, child.ParentId);

                    if (loadNewParent)
                    {
                        Assert.Same(newParent, child.Parent);
                        Assert.Contains(child, newParent.Children);
                    }
                    else
                    {
                        Assert.Null((child.Parent));
                    }
                }
            },
                context =>
            {
                if (!Fixture.ForceClientNoAction &&
                    !Fixture.NoStoreCascades)
                {
                    Assert.Null(context.Set <Optional1>().Find(removedId));

                    var child     = context.Set <Optional2>().Find(childId);
                    var newParent = loadNewParent ? context.Set <Optional1>().Find(newFk) : null;

                    Assert.Equal(newFk, child.ParentId);

                    if (loadNewParent)
                    {
                        Assert.Same(newParent, child.Parent);
                        Assert.Contains(child, newParent.Children);
                    }
                    else
                    {
                        Assert.Null((child.Parent));
                    }

                    Assert.False(context.ChangeTracker.HasChanges());
                }
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeTracker" /> class.
 /// </summary>
 /// <param name="autoDetectChangesEnabled">autoDetectChangesEnabled.</param>
 /// <param name="lazyLoadingEnabled">lazyLoadingEnabled.</param>
 /// <param name="queryTrackingBehavior">queryTrackingBehavior.</param>
 /// <param name="deleteOrphansTiming">deleteOrphansTiming.</param>
 /// <param name="cascadeDeleteTiming">cascadeDeleteTiming.</param>
 /// <param name="context">context.</param>
 /// <param name="debugView">debugView.</param>
 public ChangeTracker(bool autoDetectChangesEnabled = default(bool), bool lazyLoadingEnabled = default(bool), QueryTrackingBehavior?queryTrackingBehavior = default(QueryTrackingBehavior?), CascadeTiming?deleteOrphansTiming = default(CascadeTiming?), CascadeTiming?cascadeDeleteTiming = default(CascadeTiming?), DbContext context = default(DbContext), DebugView debugView = default(DebugView))
 {
     this.AutoDetectChangesEnabled = autoDetectChangesEnabled;
     this.LazyLoadingEnabled       = lazyLoadingEnabled;
     this.QueryTrackingBehavior    = queryTrackingBehavior;
     this.DeleteOrphansTiming      = deleteOrphansTiming;
     this.CascadeDeleteTiming      = cascadeDeleteTiming;
     this.Context   = context;
     this.DebugView = debugView;
 }
Пример #19
0
 public override void Sever_required_one_to_one_with_alternate_key(
     ChangeMechanism changeMechanism,
     CascadeTiming?deleteOrphansTiming)
 {
     // Cascade delete not supported by in-memory database
 }
Пример #20
0
 public override void Save_removed_required_many_to_one_dependents(
     ChangeMechanism changeMechanism,
     CascadeTiming?deleteOrphansTiming)
 {
     // Cascade delete not supported by in-memory database
 }
Пример #21
0
 public override DbUpdateException Required_One_to_one_with_AK_relationships_are_one_to_one(
     CascadeTiming?deleteOrphansTiming)
 {
     // FK uniqueness not enforced in in-memory database
     return(null);
 }