public void Changed(DesignTable table = null) { _schema.Changed = true; if (table != null) { table.Changed = true; } }
public DesignTable CreateTable(DesignSchema schema, string name = null) { _schema = schema; Table = new DesignTable { Name = name ?? "New Table", Changed = true, IsNew = true, Order = schema.Tables.Count }; SetTableDefaults(Table); return(Table); }
private void CheckNewColumnDefault(DesignTable table) { if (table != null) { var last = table.Columns.Last(); if (!last.IsEmpty()) { table.Columns.Add(new DesignColumn { }); } } }
public static StoreProperty ToStoreProperty(DesignSchema schema, DesignTable t, DesignColumn c) { var i = t.Columns.IndexOf(c); var result = new StoreProperty { Name = c.Name, Type = c.Type, Pk = c.Pk, Fk = !string.IsNullOrWhiteSpace(c.Reference), Nullable = c.Nullable, AutoIncrement = c.Pk, ForeignKeys = GetForeignKeysForColumn(schema, t, c), Order = i++ }; return(result); }
private void SetTableDefaults(DesignTable table) { // create Id column if (table.Columns.Count == 0) { table.Columns.Add(new DesignColumn { Disabled = true }); } // Set Id column var PkColumn = table.Columns[0]; PkColumn.Name = "Id"; PkColumn.Type = _schema.UseIntId ? "int" : "guid"; PkColumn.Pk = true; CheckNewColumnDefault(table); }
public static StoreDefinition ToStoreDefinition(DesignSchema schema, DesignTable t) { var d = new StoreDefinition { Name = t.Name, Order = t.Order, Properties = new Dictionary <string, StoreProperty>() }; int i = 0; d.Properties = t.Columns.Where(c => !c.IsEmpty()).ToDictionary(c => c.Name, c => new StoreProperty { Name = c.Name, Type = c.Type, Pk = c.Pk, Fk = !string.IsNullOrWhiteSpace(c.Reference), Nullable = c.Nullable, AutoIncrement = c.Pk, ForeignKeys = GetForeignKeysForColumn(schema, t, c), Order = i++ }); return(d); }
private string GenerateScript(DesignTable table) { var sb = new StringBuilder(); sb.AppendLine($"TABLE {table.Name} ("); foreach (var c in table.Columns) { if (c.IsEmpty()) { continue; } var nullable = c.Nullable ? "?" : ""; var reference = string.IsNullOrWhiteSpace(c.Reference) ? "" : $" {c.Reference}"; sb.AppendLine($" {c.Name} {c.Type}{nullable}{reference},"); } sb.AppendLine(")"); return(sb.ToString()); }
public static DesignSchema FromStoreSchema(StoreSchema s) { var ds = new DesignSchema { Name = s.Name, DataContextName = s.DbContextName, Namespace = s.Namespace, Version = s.Version, VersionKey = s.VersionKey, }; if (s.Settings.ContainsKey("UseIntId")) { ds.UseIntId = bool.Parse(s.Settings["UseIntId"]); } foreach (var d in s.Definitions.Values) { var t = new DesignTable() { Name = d.Name, Order = d.Order, }; ds.Tables.Add(t); t.Columns = d.Properties.Select(x => x.Value).OrderBy(x => x.Order).Select(c => new DesignColumn() { Name = c.Name, Pk = c.Pk, Type = c.Type, Nullable = c.Nullable, Reference = GetDesignForeignKey(c), }).ToList(); } return(ds); }
private static List <StoreForeignKey> GetForeignKeysForColumn(DesignSchema schema, DesignTable t, DesignColumn c) { if (!string.IsNullOrWhiteSpace(c.TableReference) && !string.IsNullOrWhiteSpace(c.ColumnReference)) { var type = schema.Tables.FirstOrDefault(t => t.Name == c.TableReference).Columns[0].Type; return((new StoreForeignKey[] { new StoreForeignKey { DefinitionName = c.TableReference, PropertyName = c.ColumnReference, Type = type } }).ToList()); } return(new List <StoreForeignKey>()); }
private void CheckReferenceColumnDefaults(DesignTable table) { }
public void Load(DesignSchema schema, DesignTable table) { _schema = schema; Table = table; }