protected virtual void PopulateParameters(DbCommand command, ColumnModification columnModification, RelationalTypeMapper typeMapper) { if (columnModification.ParameterName != null || columnModification.OriginalParameterName != null) { var property = columnModification.Property; var isKey = columnModification.IsKey || property.IsKey() || property.IsForeignKey(); // TODO: It would be nice to just pass IProperty to the type mapper, but Migrations uses its own // store model for which there is no easy way to get an IProperty. // Issue #769 var extensions = GetPropertyExtensions(property); var typeMapping = typeMapper .GetTypeMapping(extensions.ColumnType, extensions.Column, property.ClrType, isKey, property.IsConcurrencyToken); if (columnModification.ParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, false)); } if (columnModification.OriginalParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, true)); } } }
private DbCommand CreateStoreCommand([NotNull] DbConnection connection, [NotNull] ModificationCommandBatch commandBatch) { var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = commandBatch.CompileBatch(_sqlGenerator); foreach (var columnModification in commandBatch.ModificationCommands.SelectMany(t => t.ColumnModifications)) { if (columnModification.ParameterName != null) { // TODO: It would be nice to just pass IProperty to the type mapper, but Migrations uses its own // store model for which there is no easy way to get an IProperty. var property = columnModification.Property; // TODO: Avoid doing Contains check everywhere we need to know if a property is part of a key var isKey = property.EntityType.GetKey().Properties.Contains(property); command.Parameters.Add( _typeMapper .GetTypeMapping( property.ColumnType(), property.StorageName, property.PropertyType, isKey, property.IsConcurrencyToken) .CreateParameter(command, columnModification)); } } return(command); }
public virtual void Generate([NotNull] CreateSequenceOperation createSequenceOperation, [NotNull] SqlBatchBuilder batchBuilder) { Check.NotNull(createSequenceOperation, "createSequenceOperation"); Check.NotNull(batchBuilder, "batchBuilder"); var dataType = _typeMapper.GetTypeMapping( null, createSequenceOperation.SequenceName, createSequenceOperation.Type, isKey: false, isConcurrencyToken: false).StoreTypeName; EnsureSchema(createSequenceOperation.SequenceName.Schema, batchBuilder); batchBuilder .Append("CREATE SEQUENCE ") .Append(DelimitIdentifier(createSequenceOperation.SequenceName)) .Append(" AS ") .Append(dataType) .Append(" START WITH ") .Append(createSequenceOperation.StartValue) .Append(" INCREMENT BY ") .Append(createSequenceOperation.IncrementBy); }
public virtual string GenerateDataType([NotNull] Column column) { Check.NotNull(column, "column"); if (!string.IsNullOrEmpty(column.DataType)) { return(column.DataType); } var isKey = column.Table.PrimaryKey != null && column.Table.PrimaryKey.Columns.Contains(column); return(_typeMapper.GetTypeMapping(column.DataType, column.Name, column.ClrType, isKey, column.IsTimestamp).StoreTypeName); }
public virtual string GenerateDataType(SchemaQualifiedName tableName, [NotNull] Column column) { Check.NotNull(column, "column"); if (!string.IsNullOrEmpty(column.DataType)) { return(column.DataType); } var table = Database.GetTable(tableName); var isKey = table.PrimaryKey != null && table.PrimaryKey.Columns.Contains(column) || table.ForeignKeys.SelectMany(k => k.Columns).Contains(column); return(_typeMapper.GetTypeMapping(column.DataType, column.Name, column.ClrType, isKey, column.IsTimestamp).StoreTypeName); }
protected virtual DbCommand CreateStoreCommand( [NotNull] DbTransaction transaction, [NotNull] RelationalTypeMapper typeMapper) { var command = transaction.Connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = _sql; command.Transaction = transaction; foreach (var columnModification in ModificationCommands.SelectMany(t => t.ColumnModifications)) { if (columnModification.ParameterName != null || columnModification.OriginalParameterName != null) { // TODO: It would be nice to just pass IProperty to the type mapper, but Migrations uses its own // store model for which there is no easy way to get an IProperty. var property = columnModification.Property; // TODO: Perf: Avoid doing Contains check everywhere we need to know if a property is part of a foreign key var isKey = columnModification.IsKey || property.IsForeignKey(); var typeMapping = typeMapper .GetTypeMapping( property.ColumnType(), property.ColumnName(), property.PropertyType, isKey, property.IsConcurrencyToken); if (columnModification.ParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, useOriginalValue: false)); } if (columnModification.OriginalParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, useOriginalValue: true)); } } } return(command); }
protected virtual void PopulateParameters(DbCommand command, ColumnModification columnModification, RelationalTypeMapper typeMapper) { if (columnModification.ParameterName != null || columnModification.OriginalParameterName != null) { var property = columnModification.Property; var isKey = columnModification.IsKey || property.IsKey() || property.IsForeignKey(); // TODO: It would be nice to just pass IProperty to the type mapper, but Migrations uses its own // store model for which there is no easy way to get an IProperty. // Issue #769 var extensions = GetPropertyExtensions(property); var typeMapping = typeMapper .GetTypeMapping(extensions.ColumnType, extensions.Column, property.ClrType, isKey, property.IsConcurrencyToken); if (columnModification.ParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, false)); } if (columnModification.OriginalParameterName != null) { command.Parameters.Add(typeMapping.CreateParameter(command, columnModification, true)); } } }