From 262fd00afd11c32f1595b9184ce66005b092c92b Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Mon, 23 May 2022 13:27:18 -0700 Subject: [PATCH] fix memory optimized option inconsistent state (#1503) * disable mem optimized instead of removing options * bump DacFx --- Packages.props | 2 +- .../TableDesigner/TableDesignerService.cs | 6 +---- .../TableDesigner/TableDesignerValidator.cs | 27 +++++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Packages.props b/Packages.props index c48781a8..28db7d83 100644 --- a/Packages.props +++ b/Packages.props @@ -21,7 +21,7 @@ - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index f49975ef..b7e2eff0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -767,7 +767,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner // Memory-optimized related properties tableViewModel.IsMemoryOptimized.Checked = table.IsMemoryOptimized; - tableViewModel.IsMemoryOptimized.Enabled = table.CanEditIsMemoryOptimized; + tableViewModel.IsMemoryOptimized.Enabled = table.CanEditIsMemoryOptimized || (table.IsMemoryOptimized && !tableDesigner.IsMemoryOptimizedTableSupported); tableViewModel.Durability.Enabled = table.CanEditDurability; tableViewModel.Durability.Value = SqlTableDurabilityUtil.Instance.GetName(table.Durability); tableViewModel.Durability.Values = SqlTableDurabilityUtil.Instance.DisplayNames; @@ -1358,10 +1358,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner private void SetMemoryOptimizedTableViewInfo(TableDesignerView view, Dac.TableDesigner tableDesigner) { - if (!tableDesigner.IsMemoryOptimizedTableSupported) - { - return; - } view.AdditionalTableProperties.Add(new DesignerDataPropertyInfo() { PropertyName = TablePropertyNames.IsMemoryOptimized, diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerValidator.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerValidator.cs index 69b51ca0..858221fb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerValidator.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerValidator.cs @@ -22,6 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner new NoDuplicateIndexNameRule(), new EdgeConstraintMustHaveClausesRule(), new EdgeConstraintNoRepeatingClausesRule(), + new MemoryOptimizedCannotBeEnabledWhenNotSupportedRule(), new MemoryOptimizedTableMustHaveNonClusteredPrimaryKeyRule(), new TemporalTableMustHavePeriodColumns(), new PeriodColumnsRule(), @@ -518,8 +519,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { errors.Add(new TableDesignerIssue() { - Description = "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. Please refer to https://docs.microsoft.com/sql/relational-databases/tables/graph-edge-constraints for more details.", - Severity = Contracts.IssueSeverity.Warning + Description = "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.", + Severity = Contracts.IssueSeverity.Warning, + MoreInfoLink = "https://docs.microsoft.com/sql/relational-databases/tables/graph-edge-constraints" }); } return errors; @@ -555,4 +557,25 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner return errors; } } + + public class MemoryOptimizedCannotBeEnabledWhenNotSupportedRule : ITableDesignerValidationRule + { + public List Run(Dac.TableDesigner designer) + { + var table = designer.TableViewModel; + var errors = new List(); + if (!designer.IsMemoryOptimizedTableSupported && designer.TableViewModel.IsMemoryOptimized) + { + errors.Add(new TableDesignerIssue() + { + Description = string.Format("Memory-optimized table is not supported for this database."), + PropertyPath = new object[] { TablePropertyNames.IsMemoryOptimized }, + MoreInfoLink = designer.IsAzure + ? "https://docs.microsoft.com/en-us/azure/azure-sql/in-memory-oltp-overview" + : "https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/overview-and-usage-scenarios" + }); + } + return errors; + } + } } \ No newline at end of file