本文整理汇总了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;
}