mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
[Table Designer] Support filter predicate and included columns for index (#1619)
This commit is contained in:
@@ -8797,6 +8797,54 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexIncludedColumnsGroupTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexIncludedColumnsGroupTitle);
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexIncludedColumnsPropertyDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexIncludedColumnsPropertyDescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexIncludedColumnsAddColumn
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexIncludedColumnsAddColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexIncludedColumnsColumnPropertyName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexIncludedColumnsColumnPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexFilterPredicatePropertyDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexFilterPredicatePropertyDescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static string IndexFilterPredicatePropertyTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.IndexFilterPredicatePropertyTitle);
|
||||
}
|
||||
}
|
||||
|
||||
public static string TableDesignerColumnsDisplayValueTitle
|
||||
{
|
||||
get
|
||||
@@ -9349,6 +9397,22 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
}
|
||||
}
|
||||
|
||||
public static string ClusteredIndexCannotHaveIncludedColumnsRuleDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.ClusteredIndexCannotHaveIncludedColumnsRuleDescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ClusteredIndexCannotHaveFilterPredicateRuleDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.ClusteredIndexCannotHaveFilterPredicateRuleDescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
||||
{
|
||||
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
|
||||
@@ -9714,6 +9778,16 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
return Keys.GetString(Keys.ColumnCannotBeListedMoreThanOnceInPrimaryKeyRuleDescription, columnName);
|
||||
}
|
||||
|
||||
public static string ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(string columnName, string indexName, int rowNumber)
|
||||
{
|
||||
return Keys.GetString(Keys.ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription, columnName, indexName, rowNumber);
|
||||
}
|
||||
|
||||
public static string ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(string columnName, string indexName, int rowNumber)
|
||||
{
|
||||
return Keys.GetString(Keys.ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription, columnName, indexName, rowNumber);
|
||||
}
|
||||
|
||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Keys
|
||||
{
|
||||
@@ -13196,6 +13270,24 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
public const string IndexColumnIsAscendingPropertyTitle = "IndexColumnIsAscendingPropertyTitle";
|
||||
|
||||
|
||||
public const string IndexIncludedColumnsGroupTitle = "IndexIncludedColumnsGroupTitle";
|
||||
|
||||
|
||||
public const string IndexIncludedColumnsPropertyDescription = "IndexIncludedColumnsPropertyDescription";
|
||||
|
||||
|
||||
public const string IndexIncludedColumnsAddColumn = "IndexIncludedColumnsAddColumn";
|
||||
|
||||
|
||||
public const string IndexIncludedColumnsColumnPropertyName = "IndexIncludedColumnsColumnPropertyName";
|
||||
|
||||
|
||||
public const string IndexFilterPredicatePropertyDescription = "IndexFilterPredicatePropertyDescription";
|
||||
|
||||
|
||||
public const string IndexFilterPredicatePropertyTitle = "IndexFilterPredicatePropertyTitle";
|
||||
|
||||
|
||||
public const string TableDesignerColumnsDisplayValueTitle = "TableDesignerColumnsDisplayValueTitle";
|
||||
|
||||
|
||||
@@ -13436,6 +13528,18 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
public const string MutipleCreateTableStatementsInScriptRuleDescription = "MutipleCreateTableStatementsInScriptRuleDescription";
|
||||
|
||||
|
||||
public const string ClusteredIndexCannotHaveIncludedColumnsRuleDescription = "ClusteredIndexCannotHaveIncludedColumnsRuleDescription";
|
||||
|
||||
|
||||
public const string ClusteredIndexCannotHaveFilterPredicateRuleDescription = "ClusteredIndexCannotHaveFilterPredicateRuleDescription";
|
||||
|
||||
|
||||
public const string ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription = "ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription";
|
||||
|
||||
|
||||
public const string ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription = "ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription";
|
||||
|
||||
|
||||
private Keys()
|
||||
{ }
|
||||
|
||||
|
||||
@@ -4815,6 +4815,30 @@ The Query Processor estimates that implementing the following index could improv
|
||||
<value>Is Ascending</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexIncludedColumnsGroupTitle" xml:space="preserve">
|
||||
<value>Included Columns</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexIncludedColumnsPropertyDescription" xml:space="preserve">
|
||||
<value>The included columns of the index</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexIncludedColumnsAddColumn" xml:space="preserve">
|
||||
<value>Add Column</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexIncludedColumnsColumnPropertyName" xml:space="preserve">
|
||||
<value>Column</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexFilterPredicatePropertyDescription" xml:space="preserve">
|
||||
<value>Filter predicate of the index</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="IndexFilterPredicatePropertyTitle" xml:space="preserve">
|
||||
<value>Filter Predicate</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="TableDesignerColumnsDisplayValueTitle" xml:space="preserve">
|
||||
<value>Columns</value>
|
||||
<comment></comment>
|
||||
@@ -5146,4 +5170,22 @@ The Query Processor estimates that implementing the following index could improv
|
||||
<value>There are multiple table definitions in the script, only the first table can be edited in the designer.</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="ClusteredIndexCannotHaveIncludedColumnsRuleDescription" xml:space="preserve">
|
||||
<value>Included columns are not supported for a clustered index.</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="ClusteredIndexCannotHaveFilterPredicateRuleDescription" xml:space="preserve">
|
||||
<value>Filter predicate is not supported for a clustered index.</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription" xml:space="preserve">
|
||||
<value>Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.</value>
|
||||
<comment>.
|
||||
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </comment>
|
||||
</data>
|
||||
<data name="ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription" xml:space="preserve">
|
||||
<value>Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.</value>
|
||||
<comment>.
|
||||
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </comment>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -2286,6 +2286,12 @@ IndexIsUniquePropertyDescription = Whether the data entered into this index must
|
||||
TableDesignerIsUniquePropertyTitle = Is Unique
|
||||
IndexColumnIsAscendingPropertyDescription = Specifies the sort order of the column.
|
||||
IndexColumnIsAscendingPropertyTitle = Is Ascending
|
||||
IndexIncludedColumnsGroupTitle = Included Columns
|
||||
IndexIncludedColumnsPropertyDescription = The included columns of the index
|
||||
IndexIncludedColumnsAddColumn = Add Column
|
||||
IndexIncludedColumnsColumnPropertyName = Column
|
||||
IndexFilterPredicatePropertyDescription = Filter predicate of the index
|
||||
IndexFilterPredicatePropertyTitle = Filter Predicate
|
||||
TableDesignerColumnsDisplayValueTitle = Columns
|
||||
TableDesignerDeleteColumnConfirmationMessage = Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue?
|
||||
TableDesignerGraphTableGroupTitle = Graph Table
|
||||
@@ -2365,4 +2371,8 @@ MemoryOptimizedTableIdentityColumnRuleDescription = The use of seed and incremen
|
||||
TableShouldAvoidHavingMultipleEdgeConstraintsRuleDescription = The table has more than one edge constraint on it. This is only useful as a temporary state when modifying existing edge constraints, and should not be used in other cases.
|
||||
ColumnCannotBeListedMoreThanOnceInPrimaryKeyRuleDescription(string columnName) = Cannot use duplicate column names in primary key, column name: {0}
|
||||
MemoryOptimizedCannotBeEnabledWhenNotSupportedRuleDescription = Memory-optimized table is not supported for this database.
|
||||
MutipleCreateTableStatementsInScriptRuleDescription = There are multiple table definitions in the script, only the first table can be edited in the designer.
|
||||
MutipleCreateTableStatementsInScriptRuleDescription = There are multiple table definitions in the script, only the first table can be edited in the designer.
|
||||
ClusteredIndexCannotHaveIncludedColumnsRuleDescription = Included columns are not supported for a clustered index.
|
||||
ClusteredIndexCannotHaveFilterPredicateRuleDescription = Filter predicate is not supported for a clustered index.
|
||||
ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.
|
||||
ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.
|
||||
@@ -6254,6 +6254,58 @@ The Query Processor estimates that implementing the following index could improv
|
||||
<target state="new">Average Row Size</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexIncludedColumnsGroupTitle">
|
||||
<source>Included Columns</source>
|
||||
<target state="new">Included Columns</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexIncludedColumnsPropertyDescription">
|
||||
<source>The included columns of the index</source>
|
||||
<target state="new">The included columns of the index</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexIncludedColumnsAddColumn">
|
||||
<source>Add Column</source>
|
||||
<target state="new">Add Column</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexIncludedColumnsColumnPropertyName">
|
||||
<source>Column</source>
|
||||
<target state="new">Column</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexFilterPredicatePropertyDescription">
|
||||
<source>Filter predicate of the index</source>
|
||||
<target state="new">Filter predicate of the index</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="IndexFilterPredicatePropertyTitle">
|
||||
<source>Filter Predicate</source>
|
||||
<target state="new">Filter Predicate</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="ClusteredIndexCannotHaveIncludedColumnsRuleDescription">
|
||||
<source>Included columns are not supported for a clustered index.</source>
|
||||
<target state="new">Included columns are not supported for a clustered index.</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="ClusteredIndexCannotHaveFilterPredicateRuleDescription">
|
||||
<source>Filter predicate is not supported for a clustered index.</source>
|
||||
<target state="new">Filter predicate is not supported for a clustered index.</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription">
|
||||
<source>Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.</source>
|
||||
<target state="new">Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.</target>
|
||||
<note>.
|
||||
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </note>
|
||||
</trans-unit>
|
||||
<trans-unit id="ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription">
|
||||
<source>Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.</source>
|
||||
<target state="new">Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.</target>
|
||||
<note>.
|
||||
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </note>
|
||||
</trans-unit>
|
||||
<trans-unit id="UpdatableLedger_LabelPart">
|
||||
<source>Updatable Ledger</source>
|
||||
<target state="new">Updatable Ledger</target>
|
||||
|
||||
@@ -87,6 +87,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
public const string IsUnique = "isUnique";
|
||||
public const string IsClustered = "isClustered";
|
||||
public const string Columns = "columns";
|
||||
public const string IncludedColumns = "includedColumns";
|
||||
public const string FilterPredicate = "filterPredicate";
|
||||
public const string ColumnsDisplayValue = "columnsDisplayValue";
|
||||
}
|
||||
|
||||
@@ -96,6 +98,11 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
public const string Ascending = "ascending";
|
||||
}
|
||||
|
||||
public static class IndexIncludedColumnSpecificationPropertyNames
|
||||
{
|
||||
public const string Column = "column";
|
||||
}
|
||||
|
||||
public static class EdgeConstraintPropertyNames
|
||||
{
|
||||
public const string Name = "name";
|
||||
|
||||
@@ -17,8 +17,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
public CheckBoxProperties IsUnique { get; set; } = new CheckBoxProperties();
|
||||
|
||||
public InputBoxProperties ColumnsDisplayValue { get; set; } = new InputBoxProperties();
|
||||
public InputBoxProperties FilterPredicate { get; set; } = new InputBoxProperties();
|
||||
|
||||
public TableComponentProperties<IndexedColumnSpecification> Columns { get; set; } = new TableComponentProperties<IndexedColumnSpecification>();
|
||||
public TableComponentProperties<IndexIncludedColumnSpecification> IncludedColumns { get; set; } = new TableComponentProperties<IndexIncludedColumnSpecification>();
|
||||
}
|
||||
|
||||
public class IndexedColumnSpecification
|
||||
@@ -27,4 +29,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
|
||||
public CheckBoxProperties Ascending { get; set; } = new CheckBoxProperties();
|
||||
}
|
||||
|
||||
public class IndexIncludedColumnSpecification
|
||||
{
|
||||
public DropdownProperties Column { get; set; } = new DropdownProperties();
|
||||
}
|
||||
}
|
||||
@@ -281,6 +281,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
case IndexPropertyNames.Columns:
|
||||
table.Indexes.Items[indexL1].AddNewColumnSpecification();
|
||||
break;
|
||||
case IndexPropertyNames.IncludedColumns:
|
||||
table.Indexes.Items[indexL1].AddNewIncludedColumn();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -358,6 +361,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
case IndexPropertyNames.Columns:
|
||||
table.Indexes.Items[indexL1].RemoveColumnSpecification(indexL2);
|
||||
break;
|
||||
case IndexPropertyNames.IncludedColumns:
|
||||
table.Indexes.Items[indexL1].RemoveIncludedColumn(indexL2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -601,6 +607,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
case IndexPropertyNames.Description:
|
||||
sqlIndex.Description = GetStringValue(newValue);
|
||||
break;
|
||||
case IndexPropertyNames.FilterPredicate:
|
||||
sqlIndex.FilterPredicate = GetStringValue(newValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -686,6 +695,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IndexPropertyNames.IncludedColumns:
|
||||
switch (propertyNameL3)
|
||||
{
|
||||
case IndexIncludedColumnSpecificationPropertyNames.Column:
|
||||
sqlIndex.UpdateIncludedColumn(indexL2, GetStringValue(newValue));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -917,6 +936,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
columnSpecVM.Column.Values = tableDesigner.GetColumnsForTable(table.FullName).ToList();
|
||||
indexVM.Columns.Data.Add(columnSpecVM);
|
||||
}
|
||||
|
||||
indexVM.FilterPredicate.Value = index.FilterPredicate;
|
||||
indexVM.FilterPredicate.Enabled = !index.IsClustered || index.FilterPredicate != null;
|
||||
indexVM.IncludedColumns.Enabled = !index.IsClustered || index.IncludedColumns.Count() > 0;
|
||||
indexVM.IncludedColumns.CanAddRows = !index.IsClustered;
|
||||
|
||||
foreach (var column in index.IncludedColumns)
|
||||
{
|
||||
var includedColumnsVM = new IndexIncludedColumnSpecification();
|
||||
includedColumnsVM.Column.Value = column;
|
||||
includedColumnsVM.Column.Values = tableDesigner.GetColumnsForTable(table.FullName).ToList();
|
||||
indexVM.IncludedColumns.Data.Add(includedColumnsVM);
|
||||
}
|
||||
|
||||
indexVM.ColumnsDisplayValue.Value = index.ColumnsDisplayValue;
|
||||
indexVM.ColumnsDisplayValue.Enabled = false;
|
||||
tableViewModel.Indexes.Data.Add(indexVM);
|
||||
@@ -1185,6 +1218,43 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
{
|
||||
Title = SR.TableDesignerIsUniquePropertyTitle
|
||||
}
|
||||
},
|
||||
new DesignerDataPropertyInfo()
|
||||
{
|
||||
PropertyName = IndexPropertyNames.FilterPredicate,
|
||||
Description = SR.IndexFilterPredicatePropertyDescription,
|
||||
ComponentType = DesignerComponentType.Input,
|
||||
ComponentProperties = new InputBoxProperties()
|
||||
{
|
||||
Title = SR.IndexFilterPredicatePropertyTitle,
|
||||
Width = 200
|
||||
}
|
||||
},
|
||||
new DesignerDataPropertyInfo()
|
||||
{
|
||||
PropertyName = IndexPropertyNames.IncludedColumns,
|
||||
Description = SR.IndexIncludedColumnsPropertyDescription,
|
||||
ComponentType = DesignerComponentType.Table,
|
||||
Group = SR.IndexIncludedColumnsGroupTitle,
|
||||
ComponentProperties = new TableComponentProperties<IndexIncludedColumnSpecification>()
|
||||
{
|
||||
AriaLabel = SR.IndexIncludedColumnsGroupTitle,
|
||||
Columns = new List<string> () { IndexIncludedColumnSpecificationPropertyNames.Column},
|
||||
LabelForAddNewButton = SR.IndexIncludedColumnsAddColumn,
|
||||
ItemProperties = new List<DesignerDataPropertyInfo>()
|
||||
{
|
||||
new DesignerDataPropertyInfo()
|
||||
{
|
||||
PropertyName = IndexIncludedColumnSpecificationPropertyNames.Column,
|
||||
ComponentType = DesignerComponentType.Dropdown,
|
||||
ComponentProperties = new DropdownProperties()
|
||||
{
|
||||
Title = SR.IndexIncludedColumnsColumnPropertyName,
|
||||
Width = 150
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
view.IndexTableOptions.PropertiesToDisplay = new List<string>() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique };
|
||||
|
||||
@@ -33,7 +33,11 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
new MemoryOptimizedTableIdentityColumnRule(),
|
||||
new TableShouldAvoidHavingMultipleEdgeConstraintsRule(),
|
||||
new ColumnCannotBeListedMoreThanOnceInPrimaryKeyRule(),
|
||||
new MutipleCreateTableStatementsInScriptRule()
|
||||
new MutipleCreateTableStatementsInScriptRule(),
|
||||
new ClusteredIndexCannotHaveFilterPredicate(),
|
||||
new ClusteredIndexCannotHaveIncludedColumnsRule(),
|
||||
new ColumnCanOnlyAppearOnceInIndexIncludedColumnsRule(),
|
||||
new ColumnCannotDuplicateWitIndexKeyColumnsRule()
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -77,6 +81,50 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public class ClusteredIndexCannotHaveIncludedColumnsRule : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
{
|
||||
var table = designer.TableViewModel;
|
||||
var errors = new List<TableDesignerIssue>();
|
||||
for (int i = 0; i < table.Indexes.Items.Count; i++)
|
||||
{
|
||||
var index = table.Indexes.Items[i];
|
||||
if (index.IsClustered && index.IncludedColumns.Count != 0)
|
||||
{
|
||||
errors.Add(new TableDesignerIssue()
|
||||
{
|
||||
Description = SR.ClusteredIndexCannotHaveIncludedColumnsRuleDescription,
|
||||
PropertyPath = new object[] { TablePropertyNames.Indexes, i, IndexPropertyNames.IncludedColumns, 0 }
|
||||
});
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
public class ClusteredIndexCannotHaveFilterPredicate : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
{
|
||||
var table = designer.TableViewModel;
|
||||
var errors = new List<TableDesignerIssue>();
|
||||
for (int i = 0; i < table.Indexes.Items.Count; i++)
|
||||
{
|
||||
var index = table.Indexes.Items[i];
|
||||
if (index.IsClustered && index.FilterPredicate != null)
|
||||
{
|
||||
errors.Add(new TableDesignerIssue()
|
||||
{
|
||||
Description = SR.ClusteredIndexCannotHaveFilterPredicateRuleDescription,
|
||||
PropertyPath = new object[] { TablePropertyNames.Indexes, i, IndexPropertyNames.FilterPredicate }
|
||||
});
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
public class ForeignKeyMustHaveColumnsRule : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
@@ -130,6 +178,64 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public class ColumnCanOnlyAppearOnceInIndexIncludedColumnsRule : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
{
|
||||
var table = designer.TableViewModel;
|
||||
var errors = new List<TableDesignerIssue>();
|
||||
for (int i = 0; i < table.Indexes.Items.Count; i++)
|
||||
{
|
||||
var index = table.Indexes.Items[i];
|
||||
var existingColumns = new HashSet<string>();
|
||||
for (int j = 0; j < index.IncludedColumns.Count; j++)
|
||||
{
|
||||
var col = index.IncludedColumns[j];
|
||||
if (existingColumns.Contains(col))
|
||||
{
|
||||
errors.Add(new TableDesignerIssue()
|
||||
{
|
||||
Description = SR.ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(col, index.Name, j + 1),
|
||||
PropertyPath = new object[] { TablePropertyNames.Indexes, i, IndexPropertyNames.IncludedColumns, j }
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
existingColumns.Add(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColumnCannotDuplicateWitIndexKeyColumnsRule : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
{
|
||||
var table = designer.TableViewModel;
|
||||
var errors = new List<TableDesignerIssue>();
|
||||
for (int i = 0; i < table.Indexes.Items.Count; i++)
|
||||
{
|
||||
var index = table.Indexes.Items[i];
|
||||
var keyCols = new HashSet<string>(index.Columns.Select(s => s.Column));
|
||||
for (int j = 0; j < index.IncludedColumns.Count; j++)
|
||||
{
|
||||
var col = index.IncludedColumns[j];
|
||||
if (keyCols.Contains(col))
|
||||
{
|
||||
errors.Add(new TableDesignerIssue()
|
||||
{
|
||||
Description = SR.ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(col, index.Name, j + 1),
|
||||
PropertyPath = new object[] { TablePropertyNames.Indexes, i, IndexPropertyNames.IncludedColumns, j }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColumnCanOnlyAppearOnceInForeignKeyRule : ITableDesignerValidationRule
|
||||
{
|
||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||
|
||||
Reference in New Issue
Block a user