当前位置: 首页>>代码示例>>C#>>正文


C# TypeUsage.IsNullable方法代码示例

本文整理汇总了C#中TypeUsage.IsNullable方法的典型用法代码示例。如果您正苦于以下问题:C# TypeUsage.IsNullable方法的具体用法?C# TypeUsage.IsNullable怎么用?C# TypeUsage.IsNullable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TypeUsage的用法示例。


在下文中一共展示了TypeUsage.IsNullable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSqlParameter

        // <summary>
        // Creates a SqlParameter given a name, type, and direction
        // </summary>
        internal static SqlParameter CreateSqlParameter(
            string name, TypeUsage type, ParameterMode mode, object value, bool preventTruncation, SqlVersion version)
        {
            int? size;
            byte? precision;
            byte? scale;
            string udtTypeName;

            value = EnsureSqlParameterValue(value);

            var result = new SqlParameter(name, value);

            // .Direction
            var direction = ParameterModeToParameterDirection(mode);
            if (result.Direction != direction)
            {
                result.Direction = direction;
            }

            // .Size, .Precision, .Scale and .SqlDbType
            // output parameters are handled differently (we need to ensure there is space for return
            // values where the user has not given a specific Size/MaxLength)
            var isOutParam = mode != ParameterMode.In;
            var sqlDbType = GetSqlDbType(type, isOutParam, version, out size, out precision, out scale, out udtTypeName);

            if (result.SqlDbType != sqlDbType)
            {
                result.SqlDbType = sqlDbType;
            }

            if (sqlDbType == SqlDbType.Udt)
            {
                result.UdtTypeName = udtTypeName;
            }

            // Note that we overwrite 'facet' parameters where either the value is different or
            // there is an output parameter. This is because output parameters in SqlClient have their
            // facets clobbered if they are implicitly set (e.g. if the Size was implicitly set
            // by setting the value)
            if (size.HasValue)
            {
                // size.HasValue is always true for Output parameters
                if ((isOutParam || result.Size != size.Value))
                {
                    if (preventTruncation && size.Value != -1)
                    {
                        // To prevent truncation, set the Size of the parameter to the larger of either
                        // the declared length or the actual length for the parameter. This allows SQL
                        // Server to complain if a value is too long while preventing cache misses for
                        // values within the range.
                        result.Size = Math.Max(result.Size, size.Value);
                    }
                    else
                    {
                        result.Size = size.Value;
                    }
                }
            }
            else
            {
                var typeKind = ((PrimitiveType)type.EdmType).PrimitiveTypeKind;
                if (typeKind == PrimitiveTypeKind.String)
                {
                    result.Size = GetDefaultStringMaxLength(version, sqlDbType);
                }
                else if (typeKind == PrimitiveTypeKind.Binary)
                {
                    result.Size = GetDefaultBinaryMaxLength(version);
                }
            }
            if (precision.HasValue
                && (isOutParam || (result.Precision != precision.Value && _truncateDecimalsToScale)))
            {
                result.Precision = precision.Value;
            }
            if (scale.HasValue
                && (isOutParam || (result.Scale != scale.Value && _truncateDecimalsToScale)))
            {
                result.Scale = scale.Value;
            }

            // .IsNullable
            var isNullable = type.IsNullable();
            if (isOutParam || isNullable != result.IsNullable)
            {
                result.IsNullable = isNullable;
            }

            return result;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:93,代码来源:SqlProviderServices.cs


注:本文中的TypeUsage.IsNullable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。