Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup compiled model tooling #24932

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public virtual string ScriptDbContext(string? contextType)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNamespace, string? contextType)
public virtual void Optimize(string? outputDir, string? modelNamespace, string? contextType)
{
using var context = CreateContext(contextType);

Expand All @@ -151,7 +151,7 @@ public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNa

var finalModelNamespace = modelNamespace ?? GetNamespaceFromOutputPath(outputDir) ?? "";

var scaffoldedModel = scaffolder.ScaffoldModel(
scaffolder.ScaffoldModel(
context.GetService<IDesignTimeModel>().Model,
outputDir,
new CompiledModelCodeGenerationOptions
Expand All @@ -175,8 +175,6 @@ public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNa
{
_reporter.WriteWarning(DesignStrings.CompiledModelCustomCacheKeyFactory(cacheKeyFactory.GetType().ShortDisplayName()));
}

return scaffoldedModel;
}

private string? GetNamespaceFromOutputPath(string directoryPath)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Design/Design/OperationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public Optimize(
}
}

private IReadOnlyList<string> OptimizeImpl(string? outputDir, string? modelNamespace, string? contextType)
private void OptimizeImpl(string? outputDir, string? modelNamespace, string? contextType)
=> ContextOperations.Optimize(outputDir, modelNamespace, contextType);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Tools/EFCore.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Add-Migration
Drop-Database
Get-DbContext
Get-Migration
Remove-Migration
Optimize-DbContext
Remove-Migration
Scaffold-DbContext
Script-Migration
Update-Database
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Tools/EntityFrameworkCore.psd1.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ FunctionsToExport = (
'Enable-Migrations',
'Get-DbContext',
'Get-Migration',
'Remove-Migration',
'Optimize-DbContext',
'Remove-Migration',
'Scaffold-DbContext',
'Script-DbContext',
'Script-Migration',
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,9 @@ function Remove-Migration
#

Register-TabExpansion Optimize-DbContext @{
Provider = { param($x) GetProviders $x.Project }
Project = { GetProjects }
StartupProject = { GetProjects }
OutputDir = { <# Disabled. Otherwise, paths would be relative to the solution directory. #> }
ContextDir = { <# Disabled. Otherwise, paths would be relative to the solution directory. #> }
}

<#
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 @@ -28,10 +28,10 @@ LONG DESCRIPTION

Get-Migration Lists available migrations.

Remove-Migration Removes the last migration.

Optimize-DbContext Generates a compiled version of the model used by the DbContext.

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 DbContext. Bypasses any migrations.
Expand All @@ -45,8 +45,8 @@ SEE ALSO
Drop-Database
Get-DbContext
Get-Migration
Remove-Migration
Optimize-DbContext
Remove-Migration
Scaffold-DbContext
Script-DbContext
Script-Migration
Expand Down
2 changes: 0 additions & 2 deletions src/ef/Commands/DbContextOptimizeCommand.Configure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ internal partial class DbContextOptimizeCommand : ContextCommandBase
{
private CommandOption? _outputDir;
private CommandOption? _namespace;
private CommandOption? _json;

public override void Configure(CommandLineApplication command)
{
command.Description = Resources.DbContextOptimizeDescription;

_outputDir = command.Option("-o|--output-dir <PATH>", Resources.OutputDirDescription);
_namespace = command.Option("-n|--namespace <NAMESPACE>", Resources.NamespaceDescription);
_json = Json.ConfigureOption(command);

base.Configure(command);
}
Expand Down
28 changes: 1 addition & 27 deletions src/ef/Commands/DbContextOptimizeCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.EntityFrameworkCore.Tools.Commands
{
// ReSharper disable once ArrangeTypeModifiers
Expand All @@ -11,36 +9,12 @@ internal partial class DbContextOptimizeCommand
protected override int Execute(string[] args)
{
using var executor = CreateExecutor(args);
var result = executor.Optimize(
executor.Optimize(
_outputDir!.Value(),
_namespace!.Value(),
Context!.Value());

if (_json!.HasValue())
{
ReportJsonResults(result);
}

return base.Execute(args);
}
private static void ReportJsonResults(IReadOnlyList<string> result)
{
Reporter.WriteData("{");
Reporter.WriteData(" \"files\": [");

for (var i = 0; i < result.Count; i++)
{
var line = " " + Json.Literal(result[i]);
if (i != result.Count - 1)
{
line += ",";
}

Reporter.WriteData(line);
}

Reporter.WriteData(" ]");
Reporter.WriteData("}");
}
}
}
2 changes: 1 addition & 1 deletion src/ef/IOperationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal interface IOperationExecutor : IDisposable
IDictionary GetContextInfo(string? name);
void UpdateDatabase(string? migration, string? connectionString, string? contextType);
IEnumerable<IDictionary> GetContextTypes();
IReadOnlyList<string> Optimize(string? outputDir, string? modelNamespace, string? contextType);
void Optimize(string? outputDir, string? modelNamespace, string? contextType);

IDictionary ScaffoldContext(
string provider,
Expand Down
4 changes: 2 additions & 2 deletions src/ef/OperationExecutorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void UpdateDatabase(string? migration, string? connectionString, string?
public IEnumerable<IDictionary> GetContextTypes()
=> InvokeOperation<IEnumerable<IDictionary>>("GetContextTypes");

public IReadOnlyList<string> Optimize(string? outputDir, string? modelNamespace, string? contextType)
=> InvokeOperation<IReadOnlyList<string>>(
public void Optimize(string? outputDir, string? modelNamespace, string? contextType)
=> InvokeOperation(
"Optimize",
new Dictionary<string, object?>
{
Expand Down