Skip to content

Commit 9dec866

Browse files
authored
Merge pull request #7 from gmarginet/4-feature-request-give-the-user-the-possibility-to-generate-a-dto-class-for-the-result-of-a-query
4 feature request give the user the possibility to generate a dto class for the result of a query
2 parents 05f7469 + efb08ca commit 9dec866

28 files changed

+545
-198
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ The connection string can be set in the .csproj file you just added the sql file
3636

3737
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ConnectionString.png?raw=true)
3838

39+
As of version 1.4 you can use the the properties window to edit the connection string, you just need to select the project file in the sollution explorer and open the properties window.
40+
41+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ConnectionString_PropertiesWindow.png?raw=true)
42+
43+
3944
Now you can start writing your sql query.
4045
You can remove all comments but if you use parameters in your query you should put the parameter declarations above the 'End Of Parameter Declaration' marker.
4146
And your actual query below the marker.
@@ -62,10 +67,39 @@ The solution explorer will now look like this.
6267
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/SolutionExplorer.png?raw=true)
6368

6469
If you don't like the file suffixes or the parameter declaration marker.
65-
These can be changed via 'Tools/Options/SqlQueryTools
70+
These can be changed via 'Tools/Options/SqlQueryTools'
6671

6772
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/Options.png?raw=true)
6873

74+
### Parameters
75+
76+
By default SqlQueryTools was generating const fields for every parameter that you declared in the parameter declaration section.
77+
78+
As of version 1.4 this can be turned of in the properties window while the sql file is selected in the solution explorer.
79+
80+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/Sql_ParametersWindow.png?raw=true)
81+
82+
In 'Tools/Options/SqlQueryTools' you can change the default for new files that are created with the SqlQueryTools 'Add Sql File' context menu item.
83+
84+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/Options_Extra.png?raw=true)
85+
86+
### Poco class
87+
88+
From version 1.4 you can also ask SqlQueryTools to generate a poco class for the result that you get back from your query.
89+
90+
Lets use the following sql as an example
91+
92+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ExampleSql_Poco.png?raw=true)
93+
94+
The code generated for this sql with 'Generate Poco' turned on would be the following:
95+
96+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ExampleCode_Poco.png?raw=true)
97+
98+
You can turn on this feature at sql file level by using the properties window of the file, or change the default for new files via 'Tools/Options/SqlQueryTools'.
99+
100+
101+
102+
69103
### License
70104

71105
MIT
11.5 KB
Loading

art/ExampleCode_Poco.png

43.3 KB
Loading

art/ExampleSql_Poco.png

30.4 KB
Loading

art/Options_Extra.png

60.5 KB
Loading

art/Sql_ParametersWindow.png

10.4 KB
Loading

sqlQueryTools-CI-CD.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
displayName: 'Restore nuget packages for SqlQueryTools solution'
2727
inputs:
2828
command: 'restore'
29-
restoreSolution: '**/SqlQueryTools.sln'
29+
restoreSolution: 'src/SqlQueryTools.sln'
3030
feedsToUse: 'config'
31-
nugetConfigPath: '**/NuGet.config'
31+
nugetConfigPath: 'src/NuGet.config'
3232

3333
- task: VSBuild@1
3434
displayName: 'Build SqlQueryTools solution'
@@ -164,4 +164,4 @@ jobs:
164164
$publishManifestPath = Resolve-Path $(Build.StagingDirectory)\Artifact\publish.extension.manifest.json
165165
$Installation = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -format json | ConvertFrom-Json
166166
$vsixPublisher = Join-Path -Path $Installation.installationPath -ChildPath "VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe" -Resolve
167-
& $vsixPublisher publish -payload $payloadPath -publishManifest $publishManifestPath -personalAccessToken $pat -ignoreWarnings "VSIXValidatorWarning01,VSIXValidatorWarning02,VSIXValidatorWarning08"
167+
& $vsixPublisher publish -payload $payloadPath -publishManifest $publishManifestPath -personalAccessToken $pat -ignoreWarnings "VSIXValidatorWarning01,VSIXValidatorWarning02,VSIXValidatorWarning08"

src/SqlQueryTools.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlQueryTools", "SqlQueryTo
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CECF109E-D547-4A4E-B312-056E93D989D2}"
99
ProjectSection(SolutionItems) = preProject
10-
..\LICENSE = ..\LICENSE
10+
..\publish.extension.manifest.json = ..\publish.extension.manifest.json
1111
..\README.md = ..\README.md
12+
..\sqlQueryTools-CI-CD.yml = ..\sqlQueryTools-CI-CD.yml
1213
EndProjectSection
1314
EndProject
1415
Global

src/SqlQueryTools/Commands/AddSqlFileCommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ internal sealed class AddSqlFileCommand : BaseCommand<AddSqlFileCommand>
1515
protected override Task InitializeCompletedAsync()
1616
{
1717
Command.Supported = false;
18+
1819
return base.InitializeCompletedAsync();
1920
}
2021

2122
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
2223
{
2324
var solutionExplorer = await VS.Windows.GetSolutionExplorerWindowAsync();
24-
25-
var selectedItemList = (await solutionExplorer.GetSelectionAsync()).ToList();
25+
var selectedItems = await solutionExplorer.GetSelectionAsync();
26+
var selectedItemList = selectedItems.ToList();
2627
if (selectedItemList.Count != 1
2728
|| selectedItemList[0].Type != SolutionItemType.PhysicalFile
2829
|| selectedItemList[0].Name.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase) == false)
@@ -31,7 +32,7 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
3132
await OutputPane.WriteLineAsync("Sql file can not be added, please select a single .cs file.");
3233
return;
3334
}
34-
var selectedPhisicalFile = selectedItemList.First() as PhysicalFile;
35+
var selectedPhisicalFile = selectedItemList[0] as PhysicalFile;
3536

3637
var project = selectedPhisicalFile.ContainingProject;
3738
if (project == null)
@@ -73,10 +74,19 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
7374

7475
await project.AddNestedFileAsync(newFileFullName, selectedPhisicalFile);
7576

77+
var newPhisicalFile = project.GetPhysicalFile(newFileFullName);
78+
if (newPhisicalFile != null)
79+
{
80+
await newPhisicalFile.TrySetGenerateParameterNamesAsync(options.GenerateParameterNames);
81+
await newPhisicalFile.TrySetGeneratePocoClassAsync(options.GeneratePocoClass);
82+
}
83+
7684
await VS.Documents.OpenAsync(newFileFullName);
7785

7886
await OutputPane.ActivateAsync();
7987
await OutputPane.WriteLineAsync($"Successfully added sql file '{newFileFullName}'.");
88+
await OutputPane.WriteLineAsync();
89+
await OutputPane.WriteLineAsync($"Do you like this extension? Help spread the word by leaving a review on https://marketplace.visualstudio.com/items?itemName=GertMarginet.SqlQueryTools&ssr=false#review-details");
8090
}
8191
}
8292
}

src/SqlQueryTools/Dialogs/FileNameDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Window x:Class="SqlQueryTools.Dialogs.FileNameDialog"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="clr-namespace:SqlQueryTools.Dialogs"
4+
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
55
Title="Add new sql file" Height="250" Width="450" ResizeMode="NoResize" ShowInTaskbar="False"
66
WindowStartupLocation="CenterScreen" SizeToContent="Width"
7-
local:VsTheme.UseVsTheme="True">
7+
toolkit:Themes.UseVsTheme="True">
88
<Grid>
99
<Grid.RowDefinitions>
1010
<RowDefinition Height="auto" />
@@ -40,7 +40,7 @@
4040
<TextBox Grid.Row="2" Grid.Column="1"
4141
Name="tFileName" TextChanged="FileName_TextChanged"
4242
VerticalContentAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Stretch"
43-
Height="23" TextWrapping="Wrap" MinWidth="210" />
43+
TextWrapping="Wrap" MinWidth="210" />
4444

4545
<Button Grid.Row="2" Grid.Column="2"
4646
Name="bAddFile" IsEnabled="False" Content="Add file" Click="AddFile_Click"

0 commit comments

Comments
 (0)