示例#1
0
 public static void ExplicitSetShadowPropertiesFromDefaults(this AcrDbContext data)
 {
     data.BeforeAll.Subscribe(entries =>
     {
         foreach (var entry in entries)
         {
             foreach (var prop in entry.Properties)
             {
                 if (prop.CurrentValue == null && prop.Metadata.IsShadowProperty() && !prop.Metadata.IsNullable)
                 {
                     prop.CurrentValue = prop.Metadata.GetDefaultValue();
                 }
             }
         }
     });
 }
        public static void SoftDeletes(this AcrDbContext data)
        {
            data.WhenModelBuilding.Subscribe(x => x.SoftDeletes());
            data.BeforeEach.Subscribe(x =>
            {
                if (x.Entity is ISoftDeleteEntity softDelete)
                {
                    switch (x.State)
                    {
                    case EntityState.Added:
                        softDelete.IsDeleted = false;
                        break;

                    case EntityState.Deleted:
                        softDelete.IsDeleted = true;
                        x.State = EntityState.Modified;
                        break;
                    }
                }
            });
        }
示例#3
0
 public static void DateStamps(this AcrDbContext data) => data
 .BeforeEach
 .Where(x => x.Entity is IDateStampEntity)
 .Subscribe(x =>