Skip to content

Commit

Permalink
Merge branch 'release/5.0-rc2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Sep 10, 2020
2 parents 2163ee5 + 77c16b4 commit 100a42b
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}
}

createTableOperations = createTableGraph.TopologicalSort(
createTableOperations = (List<CreateTableOperation>)createTableGraph.TopologicalSort(
(principalCreateTableOperation, createTableOperation, cyclicAddForeignKeyOperations) =>
{
foreach (var cyclicAddForeignKeyOperation in cyclicAddForeignKeyOperations)
Expand All @@ -321,7 +321,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}
return true;
}).ToList();
});

var dropTableGraph = new Multigraph<DropTableOperation, IForeignKeyConstraint>();
dropTableGraph.AddVertices(dropTableOperations);
Expand All @@ -340,13 +340,13 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}

var newDiffContext = new DiffContext();
dropTableOperations = dropTableGraph.TopologicalSort(
dropTableOperations = (List<DropTableOperation>)dropTableGraph.TopologicalSort(
(dropTableOperation, principalDropTableOperation, foreignKeys) =>
{
dropForeignKeyOperations.AddRange(foreignKeys.SelectMany(c => Remove(c, newDiffContext)));
return true;
}).ToList();
});

return dropForeignKeyOperations
.Concat(dropTableOperations)
Expand Down Expand Up @@ -429,7 +429,6 @@ private IEnumerable<MigrationOperation> DiffAnnotations(
IRelationalModel source,
IRelationalModel target)
{
var sourceMigrationsAnnotations = source?.GetAnnotations().ToList();
var targetMigrationsAnnotations = target?.GetAnnotations().ToList();

if (source == null)
Expand All @@ -446,17 +445,18 @@ private IEnumerable<MigrationOperation> DiffAnnotations(

if (target == null)
{
sourceMigrationsAnnotations = MigrationsAnnotations.ForRemove(source).ToList();
if (sourceMigrationsAnnotations.Count > 0)
var sourceMigrationsAnnotationsForRemoved = MigrationsAnnotations.ForRemove(source).ToList();
if (sourceMigrationsAnnotationsForRemoved.Count > 0)
{
var alterDatabaseOperation = new AlterDatabaseOperation();
alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotations);
alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotationsForRemoved);
yield return alterDatabaseOperation;
}

yield break;
}

var sourceMigrationsAnnotations = source?.GetAnnotations().ToList();
if (HasDifferences(sourceMigrationsAnnotations, targetMigrationsAnnotations))
{
var alterDatabaseOperation = new AlterDatabaseOperation();
Expand Down
27 changes: 14 additions & 13 deletions src/EFCore.Tools/tools/EntityFrameworkCore.PS2.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ $versionErrorMessage = 'The Entity Framework Core Package Manager Console Tools
The name of the migration.
.PARAMETER OutputDir
The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to "Migrations".
The directory to put files in. Paths are relative to the project directory. Defaults to "Migrations".
.PARAMETER Context
The DbContext type to use.
The DbContext to use.
.PARAMETER Project
The project to use.
Expand All @@ -26,7 +26,7 @@ $versionErrorMessage = 'The Entity Framework Core Package Manager Console Tools
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
Specify to override the namespace for the migration.
The namespace to use. Matches the directory by default.
.PARAMETER Args
Arguments passed to the application.
Expand Down Expand Up @@ -89,10 +89,10 @@ function Enable-Migrations

<#
.SYNOPSIS
Gets information about DbContext types.
Lists and gets information about available DbContext types.
.DESCRIPTION
Gets information about DbContext types.
Lists and gets information about available DbContext types.
.PARAMETER Context
The DbContext to use.
Expand Down Expand Up @@ -129,6 +129,7 @@ function Get-DbContext(
The connection string to the database. Defaults to the one specified in AddDbContext or OnConfiguring.
.PARAMETER NoConnect
Don't connect to the database.
.PARAMETER Context
The DbContext to use.
Expand Down Expand Up @@ -213,10 +214,10 @@ function Remove-Migration(
The directory to put files in. Paths are relative to the project directory.
.PARAMETER ContextDir
The directory to put DbContext file in. Paths are relative to the project directory.
The directory to put the DbContext file in. Paths are relative to the project directory.
.PARAMETER Context
The name of the DbContext to generate.
The name of the DbContext. Defaults to the database name.
.PARAMETER Schemas
The schemas of tables to generate entity types for.
Expand All @@ -234,7 +235,7 @@ function Remove-Migration(
Overwrite existing files.
.PARAMETER NoOnConfiguring
Suppress generation of the DbContext.OnConfiguring() method.
Don't generate DbContext.OnConfiguring.
.PARAMETER Project
The project to use.
Expand All @@ -243,10 +244,10 @@ function Remove-Migration(
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
Specify to override the namespace for the generated entity types.
The namespace to use. Matches the directory by default.
.PARAMETER ContextNamespace
Specify to override the namespace for the DbContext class.
The namespace of the DbContext class. Matches the directory by default.
.PARAMETER NoPluralize
Don't use the pluralizer.
Expand Down Expand Up @@ -281,10 +282,10 @@ function Scaffold-DbContext(

<#
.SYNOPSIS
Generates a SQL script from current DbContext.
Generates a SQL script from the DbContext. Bypasses any migrations.
.DESCRIPTION
Generates a SQL script from current DbContext.
Generates a SQL script from the DbContext. Bypasses any migrations.
.PARAMETER Output
The file to write the result to.
Expand Down Expand Up @@ -325,7 +326,7 @@ function Script-DbContext(
The starting migration. Defaults to '0' (the initial database).
.PARAMETER To
The ending migration. Defaults to the last migration.
The target migration. Defaults to the last migration.
.PARAMETER Idempotent
Generate a script that can be used on a database at any migration.
Expand Down
27 changes: 14 additions & 13 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Register-TabExpansion Add-Migration @{
The name of the migration.
.PARAMETER OutputDir
The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to "Migrations".
The directory to put files in. Paths are relative to the project directory. Defaults to "Migrations".
.PARAMETER Context
The DbContext type to use.
The DbContext to use.
.PARAMETER Project
The project to use.
Expand All @@ -34,7 +34,7 @@ Register-TabExpansion Add-Migration @{
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
Specify to override the namespace for the migration.
The namespace to use. Matches the directory by default.
.PARAMETER Args
Arguments passed to the application.
Expand Down Expand Up @@ -167,10 +167,10 @@ Register-TabExpansion Get-DbContext @{

<#
.SYNOPSIS
Gets information about DbContext types.
Lists and gets information about available DbContext types.
.DESCRIPTION
Gets information about DbContext types.
Lists and gets information about available DbContext types.
.PARAMETER Context
The DbContext to use.
Expand Down Expand Up @@ -237,6 +237,7 @@ Register-TabExpansion Get-Migration @{
The connection string to the database. Defaults to the one specified in AddDbContext or OnConfiguring.
.PARAMETER NoConnect
Don't connect to the database.
.PARAMETER Context
The DbContext to use.
Expand Down Expand Up @@ -393,10 +394,10 @@ Register-TabExpansion Scaffold-DbContext @{
The directory to put files in. Paths are relative to the project directory.
.PARAMETER ContextDir
The directory to put DbContext file in. Paths are relative to the project directory.
The directory to put the DbContext file in. Paths are relative to the project directory.
.PARAMETER Context
The name of the DbContext to generate.
The name of the DbContext. Defaults to the database name.
.PARAMETER Schemas
The schemas of tables to generate entity types for.
Expand All @@ -414,7 +415,7 @@ Register-TabExpansion Scaffold-DbContext @{
Overwrite existing files.
.PARAMETER NoOnConfiguring
Suppress generation of the DbContext.OnConfiguring() method.
Don't generate DbContext.OnConfiguring.
.PARAMETER Project
The project to use.
Expand All @@ -423,10 +424,10 @@ Register-TabExpansion Scaffold-DbContext @{
The startup project to use. Defaults to the solution's startup project.
.PARAMETER Namespace
Specify to override the namespace for the generated entity types.
The namespace to use. Matches the directory by default.
.PARAMETER ContextNamespace
Specify to override the namespace for the DbContext class.
The namespace of the DbContext class. Matches the directory by default.
.PARAMETER NoPluralize
Don't use the pluralizer.
Expand Down Expand Up @@ -540,10 +541,10 @@ Register-TabExpansion Script-DbContext @{

<#
.SYNOPSIS
Generates a SQL script from current DbContext.
Generates a SQL script from the DbContext. Bypasses any migrations.
.DESCRIPTION
Generates a SQL script from current DbContext.
Generates a SQL script from the DbContext. Bypasses any migrations.
.PARAMETER Output
The file to write the result to.
Expand Down Expand Up @@ -625,7 +626,7 @@ Register-TabExpansion Script-Migration @{
The starting migration. Defaults to '0' (the initial database).
.PARAMETER To
The ending migration. Defaults to the last migration.
The target migration. Defaults to the last migration.
.PARAMETER Idempotent
Generate a script that can be used on a database at any migration.
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Tools/tools/about_EntityFrameworkCore.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ LONG DESCRIPTION

Drop-Database Drops the database.

Get-DbContext Gets information about a DbContext type.
Get-DbContext Lists and gets information about available DbContext types.

Get-Migration Lists the migrations in the migration assembly.
Get-Migration Lists available migrations.

Remove-Migration Removes the last migration.

Scaffold-DbContext Scaffolds a DbContext and entity types for a database.

Script-DbContext Generates a SQL script from the current DbContext.
Script-DbContext Generates a SQL script from the DbContext. Bypasses any migrations.

Script-Migration Generates a SQL script from migrations.

Expand Down
40 changes: 21 additions & 19 deletions src/EFCore/Query/EntityShaperExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,40 +111,42 @@ protected virtual LambdaExpression GenerateMaterializationCondition([NotNull] IE
discriminatorProperty.ClrType, discriminatorProperty.GetIndex(), discriminatorProperty))
};

var switchCases = new SwitchCase[concreteEntityTypes.Length];
for (var i = 0; i < concreteEntityTypes.Length; i++)
{
var discriminatorValue = Constant(concreteEntityTypes[i].GetDiscriminatorValue(), discriminatorProperty.ClrType);
switchCases[i] = SwitchCase(Constant(concreteEntityTypes[i], typeof(IEntityType)), discriminatorValue);
}

var exception = Block(
Throw(
Call(
_createUnableToDiscriminateException, Constant(entityType),
Convert(discriminatorValueVariable, typeof(object)))),
Constant(null, typeof(IEntityType)));


var discriminatorComparer = discriminatorProperty.GetKeyValueComparer();
if (discriminatorComparer.IsDefault())
{
var switchCases = new SwitchCase[concreteEntityTypes.Length];
for (var i = 0; i < concreteEntityTypes.Length; i++)
{
var discriminatorValue = Constant(concreteEntityTypes[i].GetDiscriminatorValue(), discriminatorProperty.ClrType);
switchCases[i] = SwitchCase(Constant(concreteEntityTypes[i], typeof(IEntityType)), discriminatorValue);
}

expressions.Add(Switch(discriminatorValueVariable, exception, switchCases));
}
else
{
var staticComparer = typeof(StaticDiscriminatorComparer<,,>).MakeGenericType(
discriminatorProperty.DeclaringEntityType.ClrType,
discriminatorProperty.ClrType,
discriminatorProperty.GetTypeMapping().Converter.ProviderClrType);

var comparerField = staticComparer.GetField(nameof(StaticDiscriminatorComparer<int, int, int>.Comparer));
comparerField.SetValue(null, discriminatorComparer);

var equalsMethod = staticComparer.GetMethod(nameof(StaticDiscriminatorComparer<int, int, int>.DiscriminatorEquals));
expressions.Add(Switch(discriminatorValueVariable, exception, equalsMethod, switchCases));
Expression conditions = exception;
for (var i = concreteEntityTypes.Length - 1; i >= 0; i--)
{
conditions = Condition(
discriminatorComparer.ExtractEqualsBody(
discriminatorValueVariable,
Constant(
concreteEntityTypes[i].GetDiscriminatorValue(),
discriminatorProperty.ClrType)),
Constant(concreteEntityTypes[i], typeof(IEntityType)),
conditions);
}

expressions.Add(conditions);
}

body = Block(new[] { discriminatorValueVariable }, expressions);
}
else
Expand Down
35 changes: 0 additions & 35 deletions src/EFCore/Query/Internal/StaticDiscriminatorComparer.cs

This file was deleted.

Loading

0 comments on commit 100a42b

Please sign in to comment.