本文整理汇总了C#中System.Data.Entity.Migrations.History.HistoryRepository.CreateDiscoveryQueryTrees方法的典型用法代码示例。如果您正苦于以下问题:C# HistoryRepository.CreateDiscoveryQueryTrees方法的具体用法?C# HistoryRepository.CreateDiscoveryQueryTrees怎么用?C# HistoryRepository.CreateDiscoveryQueryTrees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Migrations.History.HistoryRepository
的用法示例。
在下文中一共展示了HistoryRepository.CreateDiscoveryQueryTrees方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_create_count_query_command_tree
public void Can_create_count_query_command_tree()
{
ResetDatabase();
var historyRepository
= new HistoryRepository(Mock.Of<InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory);
var commandTrees = historyRepository.CreateDiscoveryQueryTrees();
foreach (var commandTree in commandTrees)
{
Assert.NotNull(commandTree);
Assert.Equal(DataSpace.SSpace, commandTree.DataSpace);
Assert.Equal(0, commandTree.Parameters.Count());
}
}
示例2: Generate_can_handle_update_database_operations
public void Generate_can_handle_update_database_operations()
{
var migrationSqlGenerator = new SqlServerMigrationSqlGenerator();
var historyRepository
= new HistoryRepository(
Mock.Of<InternalContextForMock>(),
new SqlConnectionFactory().CreateConnection("Foo").ConnectionString,
DbProviderFactories.GetFactory(ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName),
"MyKey",
null,
HistoryContext.DefaultFactory,
schemas: new[] { "dbo", "foo", "bar" });
var updateDatabaseOperation
= new UpdateDatabaseOperation(historyRepository.CreateDiscoveryQueryTrees().ToList());
updateDatabaseOperation.AddMigration(
"V1",
new MigrationOperation[]
{
new DropColumnOperation("Customers", "Foo"),
new CreateProcedureOperation("Foo", "Bar")
});
updateDatabaseOperation.AddMigration(
"V2",
new MigrationOperation[]
{
new AddColumnOperation("Customers", new ColumnModel(PrimitiveTypeKind.String) { Name = "C" }),
new CreateProcedureOperation("bar", "baz")
});
var sql = migrationSqlGenerator.Generate(new[] { updateDatabaseOperation }, "2008").Join(s => s.Sql, Environment.NewLine);
Assert.Equal(@"DECLARE @CurrentMigration [nvarchar](max)
IF object_id('[dbo].[__MigrationHistory]') IS NOT NULL
SELECT @CurrentMigration =
(SELECT TOP (1)
[Project1].[MigrationId] AS [MigrationId]
FROM ( SELECT
[Extent1].[MigrationId] AS [MigrationId]
FROM [dbo].[__MigrationHistory] AS [Extent1]
WHERE [Extent1].[ContextKey] = N'MyKey'
) AS [Project1]
ORDER BY [Project1].[MigrationId] DESC)
IF object_id('[foo].[__MigrationHistory]') IS NOT NULL
SELECT @CurrentMigration =
(SELECT TOP (1)
[Project1].[MigrationId] AS [MigrationId]
FROM ( SELECT
[Extent1].[MigrationId] AS [MigrationId]
FROM [foo].[__MigrationHistory] AS [Extent1]
WHERE [Extent1].[ContextKey] = N'MyKey'
) AS [Project1]
ORDER BY [Project1].[MigrationId] DESC)
IF object_id('[bar].[__MigrationHistory]') IS NOT NULL
SELECT @CurrentMigration =
(SELECT TOP (1)
[Project1].[MigrationId] AS [MigrationId]
FROM ( SELECT
[Extent1].[MigrationId] AS [MigrationId]
FROM [bar].[__MigrationHistory] AS [Extent1]
WHERE [Extent1].[ContextKey] = N'MyKey'
) AS [Project1]
ORDER BY [Project1].[MigrationId] DESC)
IF @CurrentMigration IS NULL
SET @CurrentMigration = '0'
IF @CurrentMigration < 'V1'
BEGIN
DECLARE @var0 nvarchar(128)
SELECT @var0 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'Customers')
AND col_name(parent_object_id, parent_column_id) = 'Foo';
IF @var0 IS NOT NULL
EXECUTE('ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + ']')
ALTER TABLE [Customers] DROP COLUMN [Foo]
EXECUTE('
CREATE PROCEDURE [Foo]
AS
BEGIN
Bar
END
')
END
IF @CurrentMigration < 'V2'
BEGIN
ALTER TABLE [Customers] ADD [C] [nvarchar](max)
EXECUTE('
CREATE PROCEDURE [bar]
AS
BEGIN
baz
//.........这里部分代码省略.........
示例3: Can_create_count_query_command_trees_when_sql_azure_execution_strategy
public void Can_create_count_query_command_trees_when_sql_azure_execution_strategy()
{
ResetDatabase();
try
{
MutableResolver.AddResolver<Func<IDbExecutionStrategy>>(
key => (Func<IDbExecutionStrategy>)(() => new SqlAzureExecutionStrategy()));
var historyRepository
= new HistoryRepository(Mock.Of<InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory);
var commandTrees = historyRepository.CreateDiscoveryQueryTrees();
foreach (var commandTree in commandTrees)
{
Assert.NotNull(commandTree);
Assert.Equal(DataSpace.SSpace, commandTree.DataSpace);
Assert.Equal(0, commandTree.Parameters.Count());
}
}
finally
{
MutableResolver.ClearResolvers();
}
}