コード例 #1
0
ファイル: BaseContext.cs プロジェクト: farleyrw/CoreSite
        public void SyncChangeTracking()
        {
            foreach (var entry in this.ChangeTracker.Entries <IBaseEntity>())
            {
                entry.Entity.ModelState = ModelState.Unchanged;

                var originalValues = BaseContextHelper.BuildOriginalValues(entry.Entity.GetType(), this.Entry(entry.Entity).OriginalValues);

                entry.Entity.SetOriginalValues(originalValues);
            }
        }
コード例 #2
0
        public void BuildOriginalValues()
        {
            var model = new TestModel
            {
                Id       = 123,
                IsActive = true,
                Name     = "test"
            };

            var properties = A.Fake <PropertyValues>(options => options.CallsBaseMethods());

            properties.SetValues(model);

            var result = BaseContextHelper.BuildOriginalValues(model.GetType(), properties);

            result.Should().BeEquivalentTo(new Dictionary <string, object>
            {
                { "Id", 123 },
                { "IsActive", true },
                { "Name", "test" }
            });
        }
コード例 #3
0
ファイル: BaseContext.cs プロジェクト: farleyrw/CoreSite
        // For testing?
        //public new void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        // If not configured when constructed set to use Sql server.
        //if (!optionsBuilder.IsConfigured && !string.IsNullOrEmpty(this.ConnectionName))
        //{
        //	string connection = null;// ConfigurationManager.ConnectionStrings[this.ConnectionName].ConnectionString;

        //	optionsBuilder.UseSqlServer(connection);
        //}
        //base.OnConfiguring(optionsBuilder);

        //this.ChangeTracker.Tracked += this.OnObjectMaterialized;
        //}

        public void ApplyChanges <TEntity>(TEntity entity) where TEntity : class, IBaseEntity
        {
            this.Set <TEntity>().Add(entity);

            BaseContextHelper.ApplyChanges(this.ChangeTracker);
        }