Beispiel #1
0
        protected virtual void PopulateParameters(DbCommand command, ColumnModification columnModification, IRelationalTypeMapper typeMapper)
        {
            var parameterName         = columnModification.ParameterName;
            var originalParameterName = columnModification.OriginalParameterName;

            if (parameterName != null ||
                originalParameterName != null)
            {
                var property = columnModification.Property;

                var typeMapping = typeMapper.MapPropertyType(property);

                if (parameterName != null)
                {
                    command.Parameters.Add(
                        typeMapping.CreateParameter(command, parameterName, columnModification.Value, property.IsNullable));
                }

                if (originalParameterName != null)
                {
                    command.Parameters.Add(
                        typeMapping.CreateParameter(command, originalParameterName, columnModification.OriginalValue, property.IsNullable));
                }
            }
        }
        protected virtual void ColumnDefinition(
            [CanBeNull] string schema,
            [CanBeNull] string table,
            [NotNull] string name,
            [NotNull] Type clrType,
            [CanBeNull] string type,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            [NotNull] IAnnotatable annotatable,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                var property = FindProperty(model, schema, table, name);
                type = property != null
                    ? _typeMapper.MapPropertyType(property).DefaultTypeName
                    : _typeMapper.GetDefaultMapping(clrType).DefaultTypeName;
            }

            builder
            .Append(Sql.DelimitIdentifier(name))
            .Append(" ")
            .Append(type);

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }

            DefaultValue(defaultValue, defaultValueSql, builder);
        }