コード例 #1
0
        /// <summary>
        ///     Creates a <see cref="DbParameter" /> with the appropriate type information configured.
        /// </summary>
        /// <param name="command"> The command the parameter should be created on. </param>
        /// <param name="name"> The name of the parameter. </param>
        /// <param name="value"> The value to be assigned to the parameter. </param>
        /// <param name="nullable"> A value indicating whether the parameter should be a nullable type. </param>
        /// <returns> The newly created parameter. </returns>
        public override DbParameter CreateParameter(DbCommand command, string name, object value, bool?nullable = null)
        {
            var parameter = command.CreateParameter();

            parameter.Direction     = ParameterDirection.Input;
            parameter.ParameterName = name;

            if (Converter != null)
            {
                value = Converter.ConvertToProvider(value);
            }

            parameter.Value = value == null
                ? DBNull.Value
                : SpatialConverter.ConvertToProvider(value);

            if (nullable.HasValue)
            {
                parameter.IsNullable = nullable.Value;
            }

            ConfigureParameter(parameter);

            return(parameter);
        }
コード例 #2
0
        public void Can_convert_exact_types_with_nullable_converter()
        {
            Assert.Equal((int?)1, _nullableUIntToNullableInt.ConvertToProvider((uint?)1));
            Assert.Equal((uint?)1, _nullableUIntToNullableInt.ConvertFromProvider((int?)1));

            Assert.Equal((int?)-1, _nullableUIntToNullableInt.ConvertToProvider((uint?)uint.MaxValue));
            Assert.Equal((uint?)uint.MaxValue, _nullableUIntToNullableInt.ConvertFromProvider((int?)-1));
        }
コード例 #3
0
        public void Can_convert_exact_types_with_non_nullable_converter()
        {
            Assert.Equal(1, _uIntToInt.ConvertToProvider((uint)1));
            Assert.Equal((uint)1, _uIntToInt.ConvertFromProvider(1));

            Assert.Equal(-1, _uIntToInt.ConvertToProvider(uint.MaxValue));
            Assert.Equal(uint.MaxValue, _uIntToInt.ConvertFromProvider(-1));
        }