public TypedTable <T> CreateTable <T>(string tableName, bool throwIfAlreadyExists = false) { var td = TableDefinition.FromType <T>(); _createTable(tableName, td, throwIfAlreadyExists); return(GetTable <T>(tableName)); }
internal static TableDefinition<T> FromTable<T>(ITable table) { var td = TableDefinition.FromType<T>(); try { var columns = new DbExecuter(table.GetConnectionString()).ExecuteReader(SQLStatements.GetColumns(table.GetConnectionString().TableName, table.GetConnectionString().SchemaName)).ToArray(); foreach (var column in columns) { Column dbCol = column.ToObject<Column>(); var col = td.GetColumnByDbName(dbCol.DbName) ?? td.GetColumnByClrName(dbCol.DbName); if (col == null) { dbCol.DotNetType = PgSqlTypeManager.GetDotNetType(dbCol.PgType); td.AddColumn(dbCol); } else { col.DbName = dbCol.DbName; col.CanBeNull = dbCol.CanBeNull; col.DefaultValue = dbCol.DefaultValue; col.Position = dbCol.Position; col.IsPrimaryKey = dbCol.IsPrimaryKey; col.MustBeUnique = dbCol.MustBeUnique; } } } catch (Exception e) { Logger.Error(e, "GetTableSchema"); throw; } return td; }