public SchemaTable EnsureSchema(Type type) { if (!_SchemaTables.ContainsKey(type)) { SchemaTable res = new SchemaTable(type); if (res.Columns.Count < 1) { _SchemaTables.Add(type, null); } else { _SchemaTables.Add(type, res); SQTable curr = Adp.GetTable(res.Table.Name); if (curr != null) { if (!res.LockSchema) { } } else if (!DisableSchemaBuild) { Adp.CreateTable(res.Table); foreach (SchemaHintForeignKey fk in res.FKeyHints) { SchemaTable fkt = EnsureSchema(fk.ForeignKey); Adp.AddForeignKey(res.GetColumnByName(fk.Storage).Column, fkt.Table.GetPrimaryKey()); } } } } return(_SchemaTables[type]); }
public SchemaTable GetSchemaForType(Type t) { // TODO: resolve inheritence here if (!_SchemaTables.ContainsKey(t)) { SchemaTable table = new SchemaTable(t); if (table.Columns.Count < 1) { _SchemaTables.Add(t, null); } else { _SchemaTables.Add(t, table); } } return(_SchemaTables[t]); }
public SchemaColumn(SchemaTable table, List <SchemaHintColumn> hints, PropertyInfo pi) { Table = table; Hints = hints; Property = pi; SQDataTypes?datatype = GetDataTypeForType(pi.PropertyType); SQColumn res = new SQColumn() { Name = pi.Name }; res.Table = table.Table; if (datatype.HasValue) { res.DataType = datatype.Value; } bool ignore = false; foreach (SchemaHintColumn colHint in hints) { if (colHint._Ignore.HasValue) { ignore = colHint._Ignore.Value; } if (colHint.ColumnName != null) { res.Name = colHint.ColumnName; } if (colHint._IsIdentity.HasValue) { res.IsIdentity = colHint._IsIdentity.Value; } if (colHint._IsPrimary.HasValue) { res.IsPrimary = colHint._IsPrimary.Value; } if (colHint._Length.HasValue) { res.Length = colHint._Length.Value; } if (colHint._Precision.HasValue) { res.Precision = colHint._Precision.Value; } if (colHint._Scale.HasValue) { res.Scale = colHint._Scale.Value; } if (colHint._DataType.HasValue) { res.DataType = colHint._DataType.Value; } if (colHint._Serialization.HasValue) { Serialization = colHint._Serialization.Value; if (Serialization == SerializationTypes.SerializeBinary) { res.DataType = SQDataTypes.Bytes; } else if (Serialization == SerializationTypes.SerializeJSON || Serialization == SerializationTypes.SerializeXML) { res.DataType = SQDataTypes.String; } } if (colHint._Nullable.HasValue) { res.Nullable = colHint._Nullable.Value; } } if (!datatype.HasValue || ignore) { return; } Column = res; }