diff --git a/Packages.props b/Packages.props
index ff2973cc..9a9bf056 100644
--- a/Packages.props
+++ b/Packages.props
@@ -20,7 +20,7 @@
-
+
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/SqlForeignKeyActionUtil.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/SqlForeignKeyActionUtil.cs
new file mode 100644
index 00000000..4fe01301
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/SqlForeignKeyActionUtil.cs
@@ -0,0 +1,56 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
+
+namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
+{
+ public static class SqlForeignKeyActionUtil
+ {
+ private static Dictionary mapping = new Dictionary();
+
+ static SqlForeignKeyActionUtil()
+ {
+ mapping.Add(SR.SqlForeignKeyAction_NoAction, SqlForeignKeyAction.NoAction);
+ mapping.Add(SR.SqlForeignKeyAction_Cascade, SqlForeignKeyAction.Cascade);
+ mapping.Add(SR.SqlForeignKeyAction_SetNull, SqlForeignKeyAction.SetNull);
+ mapping.Add(SR.SqlForeignKeyAction_SetDefault, SqlForeignKeyAction.SetDefault);
+ }
+ public static List ActionNames
+ {
+ get
+ {
+ return mapping.Keys.ToList();
+ }
+ }
+
+ public static string GetName(SqlForeignKeyAction action)
+ {
+ foreach (var key in mapping.Keys)
+ {
+ if (mapping[key] == action)
+ {
+ return key;
+ }
+ }
+ throw new NotSupportedException(SR.UnKnownSqlForeignKeyAction(action.ToString()));
+ }
+
+ public static SqlForeignKeyAction GetValue(string displayName)
+ {
+ if (mapping.ContainsKey(displayName))
+ {
+ return mapping[displayName];
+ }
+ else
+ {
+ throw new KeyNotFoundException(SR.UnKnownSqlForeignKeyAction(displayName));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
index 7c9a547a..217b6556 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
@@ -221,6 +221,41 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
tableViewModel.Columns.Data.Add(columnViewModel);
}
+ foreach (var foreignKey in table.ForeignKeys.Items)
+ {
+ var foreignKeyViewModel = new ForeignKeyViewModel();
+ foreignKeyViewModel.Name.Value = foreignKey.Name;
+ foreignKeyViewModel.Enabled.Checked = foreignKey.Enabled;
+ foreignKeyViewModel.OnDeleteAction.Value = SqlForeignKeyActionUtil.GetName(foreignKey.OnDeleteAction);
+ foreignKeyViewModel.OnDeleteAction.Values = SqlForeignKeyActionUtil.ActionNames;
+ foreignKeyViewModel.OnUpdateAction.Value = SqlForeignKeyActionUtil.GetName(foreignKey.OnUpdateAction);
+ foreignKeyViewModel.OnUpdateAction.Values = SqlForeignKeyActionUtil.ActionNames;
+ foreignKeyViewModel.PrimaryKeyTable.Value = foreignKey.PrimaryKeyTable;
+ foreignKeyViewModel.PrimaryKeyTable.Values = table.AllTables.ToList();
+ foreignKeyViewModel.IsNotForReplication.Checked = foreignKey.IsNotForReplication;
+ for (int i = 0; i < foreignKey.ForeignKeyColumns.Count; i++)
+ {
+ var foreignKeyColumn = foreignKey.ForeignKeyColumns[i];
+ var primaryKeyColumn = foreignKey.PrimaryKeyColumns[i];
+ var mapping = new ForeignKeyColumnMapping();
+ mapping.ForeignKeyColumn.Value = foreignKeyColumn;
+ mapping.ForeignKeyColumn.Values = table.Columns.Items.Select(c => c.Name).ToList();
+ mapping.PrimaryKeyColumn.Value = primaryKeyColumn;
+ mapping.PrimaryKeyColumn.Values = table.GetColumnsForTable(foreignKey.PrimaryKeyTable).ToList();
+ foreignKeyViewModel.Columns.Data.Add(mapping);
+ }
+ tableViewModel.ForeignKeys.Data.Add(foreignKeyViewModel);
+ }
+
+ foreach (var checkConstraint in table.CheckConstraints.Items)
+ {
+ var constraint = new CheckConstraintViewModel();
+ constraint.Name.Value = checkConstraint.Name;
+ constraint.Expression.Value = checkConstraint.Expression;
+ constraint.Enabled.Checked = checkConstraint.Enabled;
+ tableViewModel.CheckConstraints.Data.Add(constraint);
+ }
+
tableViewModel.Script.Enabled = false;
tableViewModel.Script.Value = table.Script;
// TODO: set other properties of the table