private string GetTemporalTableSqlDependingOnIfTableIsTemporalOrNot <TEntity>( ITableHelper <FakeDataContext> tableHelper, params Type[] entityTypesToCreateTemporalTablesFor) where TEntity : class { var options = DbContextOptionsSetup.Setup <FakeDataContext>(); using (var context = new FakeDataContext(options)) { // Register entity types to support temporal tables. entityTypesToCreateTemporalTablesFor ?.ToList() ?.ForEach(e => TemporalEntitiesCache.Add(context.Model.FindEntityType(e))); var entityType = context.Model.FindEntityType(typeof(TEntity)); var temporalTableSqlBuilder = new TemporalTableSqlBuilder <FakeDataContext>( context, new TemporalTableSqlGeneratorFactory(), tableHelper); string sql = temporalTableSqlBuilder.BuildTemporalTablesSqlForEntityTypes(new[] { entityType }); return(sql); } }
/// <summary> /// Configure all tables to be temporal by default. /// You may skip this method and register them manually by using <see cref="EntityTypeBuilderExtensions.UseTemporalTable" /> method. /// </summary> public static void UseTemporalTables(this ModelBuilder modelBuilder) { var entityTypes = modelBuilder.Model.GetEntityTypes().ToList(); foreach (var entityType in entityTypes) { TemporalEntitiesCache.Add(entityType); } }
public void AddTemporalTableTest() { var options = DbContextOptionsSetup.Setup <FakeDataContext>(); using (var context = new FakeDataContext(options)) { var entityType = context.Model.FindEntityType(typeof(User)); // Add entity type. TemporalEntitiesCache.Add(entityType); // Test if the entity type exists in the cache. Assert.IsTrue(TemporalEntitiesCache.IsEntityConfigurationTemporal(entityType)); } }
/// <summary> /// Configure temporal table for the specified entity type configuration. /// </summary> public static void UseTemporalTable <TEntity>(this EntityTypeBuilder <TEntity> entity) where TEntity : class { TemporalEntitiesCache.Add(entity.Metadata); }