public TableSymbol(string alias, ISchema schema, ISchemaTable table, bool hasAlias) { _tables.Add(alias, new Tuple <ISchema, ISchemaTable>(schema, table)); _orders.Add(alias); HasAlias = hasAlias; _fullTableName = alias; _fullSchema = schema; _fullTable = table; }
private List<PropertyInfo> GetPropertiesInfo(ISchemaTable table) { var info = from column in table.Columns let adapter = this.propertyInfoAdapterFactory.Create(column, table, this.identifierGenerationService) select new PropertyInfo( columnName : column.Name, propertyText : adapter.GetPropertyText(), constructorInitializationText : adapter.GetConstructorInitializationText(), mappingText : adapter.GetMappingText(), columnMappingText : adapter.GetColumnMapppingText()); return info.ToList(); }
public static Table GetSchemaDescription(ISchemaTable table) { var newTable = new Table("desc", new[] { new Column("Name", typeof(string), 0), new Column("Index", typeof(int), 1), new Column("Type", typeof(string), 2) }); foreach (var column in table.Columns) { newTable.Add(new ObjectsRow(new object[] { column.ColumnName, column.ColumnIndex, column.ColumnType.Name })); } return(newTable); }
public static string GetCreateTableCommand(ISchemaTable table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } var columns = table.Columns; if (columns.Count(p => p.IsPrimary) > 1) { throw new ArgumentException("primary count > 1"); } var builder = new StringBuilder(); builder.AppendFormat("Create Table [dbo].[{0}] (", table.Name); builder.AppendLine(); using (var e = columns.OrderByDescending(p => p.IsPrimary).ThenBy(p => p.Order).GetEnumerator()) { if (e.MoveNext()) { builder.Append(GetColumnCommand(table, e.Current)); while (e.MoveNext()) { builder.AppendLine(); builder.Append(","); builder.Append(GetColumnCommand(table, e.Current)); } builder.AppendLine(); } } var primaryColumn = columns.FirstOrDefault(p => p.IsPrimary); if (primaryColumn != null) { builder.AppendFormat(" Constraint [PK_{0}] Primary Key Clustered ", table.Name); builder.AppendLine(); builder.AppendLine(" ("); builder.AppendFormat(" [{0}] Asc", primaryColumn.Name); builder.AppendLine(); builder.AppendLine(" ) With (Pad_Index = Off, Statistics_Norecompute = Off, Ignore_Dup_Key = Off, Allow_Row_Locks = On, Allow_Page_Locks = On) On [Primary]"); } builder.AppendLine(") On [Primary]"); return(builder.ToString()); }
public static bool CheckTableChanged(ISchemaTable table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (!DbConnectionManager.TryGet(table.Schema.ConnectKey, out DbConnectionProvider connectionProvider)) { throw new KeyNotFoundException("not found DbProvider key:" + table.Schema.ConnectKey); } if (connectionProvider.AccessLevel == AccessLevel.ReadOnly) { throw new InvalidOperationException("DbProvider key:" + table.Schema.ConnectKey + ", read only!"); } return(CheckTableChanged(table, connectionProvider)); }
public static Table GetSpecificTableDescription(ISchemaTable table) { var newTable = new Table("desc", new[] { new Column("Name", typeof(string), 0), new Column("Index", typeof(int), 1), new Column("Type", typeof(string), 2) }); foreach (var column in table.Columns) { foreach (var complexField in CreateTypeComplexDescription(column.ColumnName, column.ColumnType)) { newTable.Add(new ObjectsRow(new object[] { complexField.FieldName, column.ColumnIndex, complexField.Type.FullName })); } } return(newTable); }
private static string GetColumnCommand(ISchemaTable table, ISchemaColumn column) { var builder = new StringBuilder(); builder.AppendFormat("[{0}] {1}", column.Name, MsSqlHelper.GetDbTypeString(column)); if (column.IsIdentity) { builder.AppendFormat(" Identity({0}, {1})", column.IdentitySeed, column.Increment); } if (column.IsPrimary || !column.IsNullable) { builder.Append(" Not"); } builder.Append(" Null"); if (!string.IsNullOrEmpty(column.DefaultValue)) { builder.AppendFormat(" Constraint [DF_{0}_{1}] Default ({2})", table.Name, column.Name, column.DefaultValue); } return(builder.ToString()); }
public static bool CheckTableChanged(ISchemaTable table, DbConnectionProvider connectionProvider) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (connectionProvider == null) { throw new ArgumentNullException(nameof(connectionProvider)); } if (connectionProvider.AccessLevel == AccessLevel.ReadOnly) { throw new InvalidOperationException("DbProvider key:" + table.Schema.ConnectKey + ", read only!"); } bool hasChanged = false; if (table.Schema.Attributes.HasFlag(EntitySchemaAttributes.CreateTable)) { if (TableExists(table, connectionProvider)) { if (table.Schema.Attributes.HasFlag(EntitySchemaAttributes.CreateColumn) || table.Schema.Attributes.HasFlag(EntitySchemaAttributes.AlterColumn) || table.Schema.Attributes.HasFlag(EntitySchemaAttributes.DropColumn)) { var dbColumns = GetDbColumnList(connectionProvider, table.Name); var columns = table.Columns; if (table.Schema.Attributes.HasFlag(EntitySchemaAttributes.DropColumn)) { foreach (var dbColumn in dbColumns) { if (!columns.Any(p => p.Name.Equals(dbColumn.Name, StringComparison.CurrentCultureIgnoreCase))) { var commandText = string.Format("Alter Table [{0}] Drop Column [{1}]", table.Name, dbColumn.Name); connectionProvider.ExecuteNonQuery(commandText); hasChanged = true; } } } foreach (var column in columns) { var dbColumn = dbColumns.FirstOrDefault(p => p.Name.Equals(column.Name, StringComparison.CurrentCultureIgnoreCase)); if (dbColumn == null) { if (table.Schema.Attributes.HasFlag(EntitySchemaAttributes.CreateColumn)) { var commandText = string.Format("Alter Table [{0}] Add [{1}] {2}", table.Name, column.Name, MsSqlHelper.GetDbTypeString(column)); connectionProvider.ExecuteNonQuery(commandText); hasChanged = true; } } else if (!dbColumn.DbType.Equals(MsSqlHelper.GetDbTypeString(column), StringComparison.CurrentCultureIgnoreCase) && table.Schema.Attributes.HasFlag(EntitySchemaAttributes.AlterColumn)) { var commandText = string.Format("Alter Table [{0}] Alter Column [{1}] {2}", table.Name, column.Name, MsSqlHelper.GetDbTypeString(column)); connectionProvider.ExecuteNonQuery(commandText); hasChanged = true; } } } } else { var commandText = GetCreateTableCommand(table); connectionProvider.ExecuteNonQuery(commandText); hasChanged = true; } } return(hasChanged); }
private static bool TableExists(ISchemaTable table, DbConnectionProvider connectionProvider) { var str = string.Format("Select * From [sys].[tables] Where [name] = '{0}'", table.Name); return(connectionProvider.ExecuteLines(str) > 0); }
public NavigationPropertyInfoAdapter(ISchemaForeignKey foreignKey, ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { this.foreignKey = foreignKey; this.table = table; this.identifierGenerationService = identifierGenerationService; }
private List<NavigationPropertyInfo> GetNavigationPropertiesInfo(ISchemaTable table) { var info = from foreignKey in table.ForeignKeys let adapter = this.navigationPropertyInfoAdapterFactory.Create(foreignKey, table, this.identifierGenerationService) select new NavigationPropertyInfo( relationshipName : foreignKey.ConstraintName, propertyText : adapter.GetPropertyText(), constructorInitializationText : adapter.GetConstructorInitializationText(), mappingText : adapter.GetMapppingText()); return info.ToList(); }
public DescSchema(string name, ISchemaTable table, ISchemaColumn[] columns) : base(name, null) { _table = table; _columns = columns; }
public EntityInfoAdapter(ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { this.table = table; this.identifierGenerationService = identifierGenerationService; }
public PropertyInfoAdapter(ISchemaColumn column, ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { this.column = column; this.table = table; this.identifierGenerationService = identifierGenerationService; }
public INavigationPropertyInfoAdapter Create(ISchemaForeignKey foreignKey, ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { return new NavigationPropertyInfoAdapter(foreignKey, table, identifierGenerationService); }
public IEntityInfoAdapter Create(ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { return new EntityInfoAdapter(table, identifierGenerationService); }
public TransitionSchema(string name, ISchemaTable table) : base(name, CreateLibrary()) { _table = table; }
public IPropertyInfoAdapter Create(ISchemaColumn column, ISchemaTable table, IIdentifierGenerationService identifierGenerationService) { return new PropertyInfoAdapter(column, table, identifierGenerationService); }