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

Modify Get-DbContext command to list DbContexts #15652

Merged
merged 1 commit into from
May 8, 2019
Merged
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
22 changes: 15 additions & 7 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ Register-TabExpansion Get-DbContext @{

<#
.SYNOPSIS
Gets information about a DbContext type.
Gets information about DbContext types.

.DESCRIPTION
Gets information about a DbContext type.
Gets information about DbContext types.

.PARAMETER Context
The DbContext to use.
Expand All @@ -172,11 +172,19 @@ function Get-DbContext
$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject

$params = 'dbcontext', 'info', '--json'
$params += GetParams $Context

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
if ($Context)
{
$params = 'dbcontext', 'info', '--json'
$params += GetParams $Context
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
}
else
{
$params = 'dbcontext', 'list', '--json'
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json | Format-Table -Property safeName -HideTableHeaders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Much easier than using a custom type with a formatting file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Brice, I am complete PowerShell noob

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like this doesn't work for scripting. The Format-Table cmdlet retuns Microsoft.PowerShell.Commands.Internal.Format objects instead of the json objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #15673

}
}

#
Expand Down