本文整理汇总了C#中System.Data.Entity.Migrations.History.HistoryRepository类的典型用法代码示例。如果您正苦于以下问题:C# HistoryRepository类的具体用法?C# HistoryRepository怎么用?C# HistoryRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HistoryRepository类属于System.Data.Entity.Migrations.History命名空间,在下文中一共展示了HistoryRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMigrationsSince_should_return_all_migrations_when_target_is_empty
public void GetMigrationsSince_should_return_all_migrations_when_target_is_empty()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory);
ExecuteOperations(GetCreateHistoryTableOperation());
var model = CreateContext<ShopContext_v1>().GetModel();
ExecuteOperations(
new[]
{
historyRepository.CreateInsertOperation("Migration1", model)
});
ExecuteOperations(
new[]
{
historyRepository.CreateInsertOperation("Migration2", model)
});
var migrations = historyRepository.GetMigrationsSince(DbMigrator.InitialDatabase);
Assert.Equal(2, migrations.Count());
Assert.Equal("Migration2", migrations.First());
}
示例2: Can_explicit_update_when_custom_history_factory
public void Can_explicit_update_when_custom_history_factory()
{
ResetDatabase();
var migrator
= CreateMigrator<ShopContext_v1>(historyContextFactory: _testHistoryContextFactoryA);
var generatedMigration
= new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");
migrator
= CreateMigrator<ShopContext_v1>(
automaticMigrationsEnabled: false,
scaffoldedMigrations: generatedMigration,
historyContextFactory: _testHistoryContextFactoryA);
migrator.Update();
Assert.True(TableExists("MigrationsCustomers"));
Assert.True(TableExists("__Migrations"));
migrator.Update("0");
Assert.False(TableExists("MigrationsCustomers"));
Assert.False(TableExists("__Migrations"));
var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
Assert.Null(historyRepository.GetLastModel());
}
示例3: GetUpgradeOperations_should_return_nothing_when_table_not_present
public void GetUpgradeOperations_should_return_nothing_when_table_not_present()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
Assert.False(historyRepository.GetUpgradeOperations().Any());
}
示例4: AppendHistoryModel_should_add_system_elements_and_normalize_namespaces
public void AppendHistoryModel_should_add_system_elements_and_normalize_namespaces()
{
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory);
var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);
modelBuilder.Entity<FakeEntity>();
var model = modelBuilder.Build(ProviderInfo).GetModel();
historyRepository.AppendHistoryModel(model, ProviderInfo);
Assert.Equal(1, model.Descendants(EdmXNames.Csdl.EntityTypeNames.Last()).Count(e => e.IsSystemAttribute() == "true"));
Assert.Equal(1, model.Descendants(EdmXNames.Msl.EntitySetMappingNames.Last()).Count(e => e.IsSystemAttribute() == "true"));
Assert.Equal(1, model.Descendants(EdmXNames.Ssdl.EntityTypeNames.Last()).Count(e => e.IsSystemAttribute() == "true"));
Assert.Equal(1, model.Descendants(EdmXNames.Ssdl.EntitySetNames.Last()).Count(e => e.IsSystemAttribute() == "true"));
}
示例5: GetUpgradeOperations_should_return_alter_migration_id_column_when_5_to_6
public void GetUpgradeOperations_should_return_alter_migration_id_column_when_5_to_6()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(Mock.Of<InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory);
var createTableOperation = GetCreateHistoryTableOperation();
createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "ContextKey"));
createTableOperation.PrimaryKey.Columns.RemoveAt(1);
ExecuteOperations(createTableOperation);
var alterColumnOperation = historyRepository.GetUpgradeOperations().OfType<AlterColumnOperation>().Single();
Assert.Equal("MigrationId", alterColumnOperation.Column.Name);
Assert.Equal(150, alterColumnOperation.Column.MaxLength);
}
示例6: GetUpgradeOperations_should_return_context_key_column_when_not_present
public void GetUpgradeOperations_should_return_context_key_column_when_not_present()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
var createTableOperation = GetCreateHistoryTableOperation();
createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "ContextKey"));
createTableOperation.PrimaryKey.Columns.RemoveAt(1);
ExecuteOperations(createTableOperation);
var addColumnOperation = historyRepository.GetUpgradeOperations().OfType<AddColumnOperation>().Single();
Assert.Equal("ContextKey", addColumnOperation.Column.Name);
Assert.Equal("MyKey", addColumnOperation.Column.DefaultValue);
Assert.Equal(512, addColumnOperation.Column.MaxLength);
Assert.False(addColumnOperation.Column.IsNullable.Value);
}
示例7: GetUpgradeOperations_should_return_add_product_version_column_when_not_present
public void GetUpgradeOperations_should_return_add_product_version_column_when_not_present()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
var createTableOperation = GetCreateHistoryTableOperation();
createTableOperation.Columns.Remove(createTableOperation.Columns.Last());
ExecuteOperations(createTableOperation);
var addColumnOperation = (AddColumnOperation)historyRepository.GetUpgradeOperations().Last();
Assert.Equal("ProductVersion", addColumnOperation.Column.Name);
Assert.Equal("0.7.0.0", addColumnOperation.Column.DefaultValue);
Assert.Equal(32, addColumnOperation.Column.MaxLength);
Assert.False(addColumnOperation.Column.IsNullable.Value);
}
示例8: Exists_should_return_true_when_database_and_table
public void Exists_should_return_true_when_database_and_table()
{
ResetDatabase();
var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
ExecuteOperations(GetCreateHistoryTableOperation());
Assert.True(historyRepository.Exists());
}
示例9: Exists_should_return_false_when_no_table
public void Exists_should_return_false_when_no_table()
{
ResetDatabase();
var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
Assert.False(historyRepository.Exists());
}
示例10: Exists_should_return_false_when_no_database
public void Exists_should_return_false_when_no_database()
{
var historyRepository
= new HistoryRepository(
ConnectionString.Replace(DatabaseProviderFixture.DefaultDatabaseName, "NoSuchDatabase"),
ProviderFactory, "MyKey", null);
Assert.False(historyRepository.Exists());
}
示例11: GetModel_should_return_model_based_on_context_key
public void GetModel_should_return_model_based_on_context_key()
{
ResetDatabase();
var historyRepository1
= new HistoryRepository(ConnectionString, ProviderFactory, "Key1", null);
var model = CreateContext<ShopContext_v1>().GetModel();
ExecuteOperations(
GetCreateHistoryTableOperation(),
historyRepository1.CreateInsertOperation("Migration 1", model));
var historyRepository2
= new HistoryRepository(ConnectionString, ProviderFactory, "Key2", null);
ExecuteOperations(
new[] { historyRepository2.CreateInsertOperation("Migration 2", model) });
model = historyRepository1.GetModel("Migration 1");
Assert.NotNull(model);
model = historyRepository2.GetModel("Migration 2");
Assert.NotNull(model);
}
示例12: GetMigrationsSince_should_return_empty_when_target_valid_but_is_latest
public void GetMigrationsSince_should_return_empty_when_target_valid_but_is_latest()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
ExecuteOperations(GetCreateHistoryTableOperation());
var model = CreateContext<ShopContext_v1>().GetModel();
ExecuteOperations(
new[]
{
historyRepository.CreateInsertOperation("Migration1", model),
historyRepository.CreateInsertOperation("Migration2", model)
});
var migrations = historyRepository.GetMigrationsSince("Migration2");
Assert.Equal(0, migrations.Count());
}
示例13: DbMigrator
internal DbMigrator(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, bool calledByCreateDatabase)
: base(null)
{
Check.NotNull(configuration, "configuration");
Check.NotNull(configuration.ContextType, "configuration.ContextType");
_configuration = configuration;
_calledByCreateDatabase = calledByCreateDatabase;
_existenceState = existenceState;
if (usersContext != null)
{
_usersContextInfo = new DbContextInfo(usersContext);
}
else
{
_usersContextInfo
= configuration.TargetDatabase == null
? new DbContextInfo(configuration.ContextType)
: new DbContextInfo(configuration.ContextType, configuration.TargetDatabase);
if (!_usersContextInfo.IsConstructible)
{
throw Error.ContextNotConstructible(configuration.ContextType);
}
}
_modelDiffer = _configuration.ModelDiffer;
var context = usersContext ?? _usersContextInfo.CreateInstance();
_usersContext = context;
try
{
_migrationAssembly
= new MigrationAssembly(
_configuration.MigrationsAssembly,
_configuration.MigrationsNamespace);
_currentModel = context.GetModel();
_connection = context.Database.Connection;
_providerFactory = DbProviderServices.GetProviderFactory(_connection);
_defaultSchema
= context.InternalContext.DefaultSchema
?? EdmModelExtensions.DefaultSchema;
_historyContextFactory
= _configuration
.GetHistoryContextFactory(_usersContextInfo.ConnectionProviderName);
_historyRepository
= new HistoryRepository(
context.InternalContext,
_usersContextInfo.ConnectionString,
_providerFactory,
_configuration.ContextKey,
_configuration.CommandTimeout,
_historyContextFactory,
schemas: new[] { _defaultSchema }.Concat(GetHistorySchemas()),
contextForInterception: _usersContext,
initialExistence: _existenceState);
_providerManifestToken
= context.InternalContext.ModelProviderInfo != null
? context.InternalContext.ModelProviderInfo.ProviderManifestToken
: DbConfiguration
.DependencyResolver
.GetService<IManifestTokenResolver>()
.ResolveManifestToken(_connection);
var modelBuilder
= context.InternalContext.CodeFirstModel.CachedModelBuilder;
_modificationCommandTreeGenerator
= new Lazy<ModificationCommandTreeGenerator>(
() =>
new ModificationCommandTreeGenerator(
modelBuilder.BuildDynamicUpdateModel(
new DbProviderInfo(
_usersContextInfo.ConnectionProviderName,
_providerManifestToken)),
CreateConnection()));
var interceptionContext = new DbInterceptionContext();
interceptionContext = interceptionContext.WithDbContext(_usersContext);
_targetDatabase
= Strings.LoggingTargetDatabaseFormat(
DbInterception.Dispatch.Connection.GetDataSource(_connection, interceptionContext),
DbInterception.Dispatch.Connection.GetDatabase(_connection, interceptionContext),
_usersContextInfo.ConnectionProviderName,
_usersContextInfo.ConnectionStringOrigin == DbConnectionStringOrigin.DbContextInfo
? Strings.LoggingExplicit
: _usersContextInfo.ConnectionStringOrigin.ToString());
_legacyContextKey = context.InternalContext.DefaultContextKey;
_emptyModel = GetEmptyModel();
//.........这里部分代码省略.........
示例14: CreateDeleteOperation_should_return_valid_history_operation
public void CreateDeleteOperation_should_return_valid_history_operation()
{
var modelBuilder = new DbModelBuilder();
var model = modelBuilder.Build(ProviderInfo);
var edmxString = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(
edmxString, new XmlWriterSettings
{
Indent = true
}))
{
EdmxWriter.WriteEdmx(model, xmlWriter);
}
var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
var historyOperation
= (HistoryOperation)historyRepository.CreateDeleteOperation("Migration1");
Assert.NotEmpty(historyOperation.Commands);
Assert.Equal(2, historyOperation.Commands.Single().Parameters.Count);
}
示例15: GetLastModel_should_return_null_when_no_data
public void GetLastModel_should_return_null_when_no_data()
{
ResetDatabase();
var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);
var modelBuilder = new DbModelBuilder();
modelBuilder.Entity<MigrationsCustomer>();
Assert.Null(historyRepository.GetLastModel());
}