public static Type SqlToClrType(this string sqlType, bool isNullable) { TypeLenMul dictValue = null; if (Mappings.TryGetValue(sqlType, out dictValue)) { return(isNullable && dictValue.ClrType != typeof(string) ? typeof(Nullable <>).MakeGenericType(dictValue.ClrType) : dictValue.ClrType); } throw new TypeLoadException(string.Format("Can not load CLR Type from {0}", sqlType)); }
public static bool EfLengthIdHalfThis(this string sqlType) { TypeLenMul dictValue = null; if (!Mappings.TryGetValue(sqlType, out dictValue)) { throw new TypeLoadException(string.Format("Can not load CLR Type from {0}", sqlType)); } return(dictValue.MultiplyBy2); }
/// <summary> /// Clr uses a MaxLength for unicode data, i.e. SQL nvarchar, nchar, ntext, which is half what is should be /// </summary> /// <param name="sqlType"></param> /// <param name="efMaxLength"></param> /// <returns></returns> public static int GetSqlMaxLengthFromEfMaxLength(this string sqlType, int?efMaxLength) { TypeLenMul dictValue = null; if (!Mappings.TryGetValue(sqlType, out dictValue)) { throw new TypeLoadException(string.Format("Can not load CLR Type from {0}", sqlType)); } if (efMaxLength != null) { //it has a MaxLength set return((int)(dictValue.MultiplyBy2 ? efMaxLength * 2 : efMaxLength)); } //otherwise we return the default length that EF applies for this sql type return(dictValue.DefaultLength); }