Ejemplo n.º 1
0
 private RelationalTypeMapping FindMappingForProperty(RelationalTypeMappingInfo mappingInfo)
 => _property != null
         ? _relationalTypeMapper.FindMapping(_property)
         : null;
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                if (clrType == typeof(float) &&
                    mappingInfo.Size != null &&
                    mappingInfo.Size <= 24 &&
                    (storeTypeNameBase.Equals("float", StringComparison.OrdinalIgnoreCase) ||
                     storeTypeNameBase.Equals("double precision", StringComparison.OrdinalIgnoreCase)))
                {
                    return(_real);
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (_namedClrMappings.TryGetValue(clrType.FullName, out var mappingFunc))
                {
                    return(mappingFunc(clrType));
                }

                if (clrType == typeof(string))
                {
                    var isAnsi        = mappingInfo.IsUnicode == false;
                    var isFixedLength = mappingInfo.IsFixedLength == true;
                    var maxSize       = isAnsi ? 8000 : 4000;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)(isAnsi ? 900 : 450) : null);
                    if (size > maxSize)
                    {
                        size = isFixedLength ? maxSize : (int?)null;
                    }

                    return(size == null
                        ? isAnsi ? _variableLengthMaxAnsiString : _variableLengthMaxUnicodeString
                        : new AseStringTypeMapping(
                               unicode: !isAnsi,
                               size: size,
                               fixedLength: isFixedLength));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_rowversion);
                    }

                    var isFixedLength = mappingInfo.IsFixedLength == true;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)900 : null);
                    if (size > 8000)
                    {
                        size = isFixedLength ? 8000 : (int?)null;
                    }

                    return(size == null
                        ? _variableLengthMaxBinary
                        : new AseByteArrayTypeMapping(size: size, fixedLength: isFixedLength));
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
 private static RelationalTypeMapping FilterByClrType(RelationalTypeMapping mapping, RelationalTypeMappingInfo mappingInfo)
 => mapping != null &&
 (mappingInfo.ClrType == null ||
  mappingInfo.ClrType == mapping.ClrType)
         ? mapping
         : null;
Ejemplo n.º 4
0
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                if (_options.ConnectionSettings.OldGuids)
                {
                    if (storeTypeName.Equals("binary(16)", StringComparison.OrdinalIgnoreCase) &&
                        clrType == typeof(Guid))
                    {
                        return(_oldGuid);
                    }
                }
                else
                {
                    if (storeTypeName.Equals("char(36)", StringComparison.OrdinalIgnoreCase) &&
                        clrType == typeof(Guid))
                    {
                        return(_uniqueidentifier);
                    }
                }

                if (mappingInfo.IsUnicode == true)
                {
                    if (_unicodeStoreTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                        _unicodeStoreTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                    {
                        return(clrType == null ||
                               mapping.ClrType == clrType
                            ? mapping
                            : null);
                    }
                }
                else
                {
                    if (storeTypeNameBase.Equals("datetime", StringComparison.OrdinalIgnoreCase))
                    {
                        if (clrType == null ||
                            clrType == typeof(DateTime))
                        {
                            return(_options.ServerVersion.SupportsDateTime6 ? _dateTime6 : _dateTime);
                        }
                        if (clrType == typeof(DateTimeOffset))
                        {
                            return(_options.ServerVersion.SupportsDateTime6 ? _dateTimeOffset6 : _dateTimeOffset);
                        }
                    }
                    else if (storeTypeNameBase.Equals("timestamp", StringComparison.OrdinalIgnoreCase))
                    {
                        if (clrType == null ||
                            clrType == typeof(DateTime))
                        {
                            return(_timeStamp6);
                        }
                        if (clrType == typeof(DateTimeOffset))
                        {
                            return(_timeStampOffset6);
                        }
                    }

                    if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                        _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                    {
                        return(clrType == null ||
                               mapping.ClrType == clrType
                            ? mapping
                            : null);
                    }
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (clrType.TryGetElementType(typeof(JsonObject <>)) != null)
                {
                    return(new MySqlJsonTypeMapping(clrType, unicode: mappingInfo.IsUnicode));
                }

                if (clrType == typeof(string))
                {
                    // Some of this logic could be moved into MySqlStringTypeMapping once EF #11896 is fixed
                    var isAnsi        = mappingInfo.IsUnicode == false;
                    var isFixedLength = mappingInfo.IsFixedLength == true;
                    var charSetSuffix = "";
                    var bytesPerChar  = isAnsi
                        ? _options.AnsiCharSetInfo.BytesPerChar
                        : _options.UnicodeCharSetInfo.BytesPerChar;

                    if (isAnsi && (
                            (mappingInfo.IsKeyOrIndex &&
                             (_options.CharSetBehavior & CharSetBehavior.AppendToAnsiIndexAndKeyColumns) != 0)
                            ||
                            (!mappingInfo.IsKeyOrIndex &&
                             (_options.CharSetBehavior & CharSetBehavior.AppendToAnsiNonIndexAndKeyColumns) != 0)
                            ))
                    {
                        charSetSuffix = $" CHARACTER SET {_options.AnsiCharSetInfo.CharSetName}";
                    }

                    if (!isAnsi && (
                            (mappingInfo.IsKeyOrIndex &&
                             (_options.CharSetBehavior & CharSetBehavior.AppendToUnicodeIndexAndKeyColumns) != 0)
                            ||
                            (!mappingInfo.IsKeyOrIndex &&
                             (_options.CharSetBehavior & CharSetBehavior.AppendToUnicodeNonIndexAndKeyColumns) != 0)
                            ))
                    {
                        charSetSuffix = $" CHARACTER SET {_options.UnicodeCharSetInfo.CharSetName}";
                    }

                    var maxSize = 8000 / bytesPerChar;

                    var size = mappingInfo.Size ??
                               (mappingInfo.IsKeyOrIndex
                                // Allow to use at most half of the max key length, so at least 2 columns can fit
                                   ? Math.Min(_options.ServerVersion.IndexMaxBytes / (bytesPerChar * 2), 255)
                                   : (int?)null);
                    if (size > maxSize)
                    {
                        size = null;
                    }

                    var dbType = isAnsi
                        ? (isFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString)
                        : (isFixedLength ? DbType.StringFixedLength : DbType.String);

                    return(new MySqlStringTypeMapping(
                               size == null
                            ? "longtext" + charSetSuffix
                            : (isFixedLength ? "char(" : "varchar(") + size + ")" + charSetSuffix,
                               dbType,
                               !isAnsi,
                               size,
                               isFixedLength));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_options.ServerVersion.SupportsDateTime6 ? _binaryRowVersion6 : _binaryRowVersion);
                    }

                    var size = mappingInfo.Size ??
                               (mappingInfo.IsKeyOrIndex ? _options.ServerVersion.IndexMaxBytes : (int?)null);

                    return(new MySqlByteArrayTypeMapping(
                               size: size,
                               fixedLength: mappingInfo.IsFixedLength == true));
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                if (clrType == typeof(float) &&
                    mappingInfo.Size != null &&
                    mappingInfo.Size <= 24 &&
                    (storeTypeNameBase.Equals("float", StringComparison.OrdinalIgnoreCase) ||
                     storeTypeNameBase.Equals("double precision", StringComparison.OrdinalIgnoreCase)))
                {
                    return(_real);
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (clrType == typeof(string))
                {
                    var isAnsi            = mappingInfo.IsUnicode == false;
                    var isFixedLength     = mappingInfo.IsFixedLength == true;
                    var baseName          = (isAnsi ? "" : "N") + (isFixedLength ? "CHAR" : "VARCHAR2");
                    var unboundedName     = isAnsi ? "CLOB" : "NCLOB";
                    var maxSize           = isAnsi ? 4000 : 2000;
                    var storeTypeModifier = (RelationalTypeMapping.StoreTypeModifierKind?)null;

                    var size = (int?)(mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (isAnsi ? 900 : 450) : maxSize));
                    if (size > maxSize)
                    {
                        size = null;
                        storeTypeModifier = RelationalTypeMapping.StoreTypeModifierKind.None;
                    }

                    return(new OracleStringTypeMapping(
                               storeTypeModifier == RelationalTypeMapping.StoreTypeModifierKind.None ? unboundedName : baseName + "(" + size + ")",
                               isAnsi ? DbType.AnsiString : (DbType?)null,
                               !isAnsi,
                               size,
                               isFixedLength,
                               storeTypeModifier));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_rowversion);
                    }

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)900 : null);
                    var storeTypeModifier = (RelationalTypeMapping.StoreTypeModifierKind?)null;
                    if (size > 2000)
                    {
                        size = null;
                        storeTypeModifier = RelationalTypeMapping.StoreTypeModifierKind.None;
                    }

                    return(new OracleByteArrayTypeMapping(
                               (size == -1 || size == null) ? "BLOB" : "RAW(" + size + ")",
                               DbType.Binary,
                               size,
                               storeTypeModifier: storeTypeModifier));
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
 protected override RelationalTypeMapping FindMapping(RelationalTypeMappingInfo mappingInfo)
 => FindRawMapping(mappingInfo)?.Clone(mappingInfo);
Ejemplo n.º 7
0
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            // Use deferred initialization to support connection (string) based type mapping in
            // design time mode (scaffolder etc.).
            if (!_initialized)
            {
                Initialize();
                _initialized = true;
            }

            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                if (_options.DefaultDataTypeMappings.ClrBoolean != MySqlBooleanType.None)
                {
                    if (_options.DefaultDataTypeMappings.ClrBoolean == MySqlBooleanType.Bit1)
                    {
                        if (storeTypeName.Equals(_bit1.StoreType, StringComparison.OrdinalIgnoreCase))
                        {
                            return(_bit1);
                        }
                    }
                    else
                    {
                        if (storeTypeName.Equals(_tinyint1.StoreType, StringComparison.OrdinalIgnoreCase))
                        {
                            return(_tinyint1);
                        }
                    }
                }

                if (MySqlGuidTypeMapping.IsValidGuidFormat(_options.ConnectionSettings.GuidFormat))
                {
                    if (storeTypeName.Equals(_guid.StoreType, StringComparison.OrdinalIgnoreCase) &&
                        (clrType == typeof(Guid) || clrType == null))
                    {
                        return(_guid);
                    }
                }

                if (storeTypeNameBase.Equals(_dateTime6.StoreTypeNameBase, StringComparison.OrdinalIgnoreCase))
                {
                    if (clrType == null ||
                        clrType == typeof(DateTime))
                    {
                        if (mappingInfo.Precision.GetValueOrDefault() > 0 ||
                            _connectionInfo.ServerVersion.SupportsDateTime6 && _options.DefaultDataTypeMappings.ClrDateTime != MySqlDateTimeType.DateTime)
                        {
                            return(_dateTime6);
                        }
                        else
                        {
                            return(_dateTime);
                        }
                    }

                    if (clrType == typeof(DateTimeOffset))
                    {
                        if (mappingInfo.Precision.GetValueOrDefault() > 0 ||
                            _connectionInfo.ServerVersion.SupportsDateTime6 && _options.DefaultDataTypeMappings.ClrDateTimeOffset != MySqlDateTimeType.DateTime)
                        {
                            return(_dateTimeOffset6);
                        }
                        else
                        {
                            return(_dateTimeOffset);
                        }
                    }
                }
                else if (storeTypeNameBase.Equals(_timeStamp6.StoreTypeNameBase, StringComparison.OrdinalIgnoreCase))
                {
                    if (clrType == null ||
                        clrType == typeof(DateTime))
                    {
                        return(_timeStamp6);
                    }

                    if (clrType == typeof(DateTimeOffset))
                    {
                        return(_timeStampOffset6);
                    }
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (clrType.TryGetElementType(typeof(JsonObject <>)) != null)
                {
                    return(new MySqlJsonTypeMapping(clrType, unicode: mappingInfo.IsUnicode));
                }

                if (clrType == typeof(string))
                {
                    // Some of this logic could be moved into MySqlStringTypeMapping once EF #11896 is fixed
                    var isNationalCharSet = storeTypeNameBase != null &&
                                            (storeTypeNameBase.Equals(_nchar.StoreTypeNameBase, StringComparison.OrdinalIgnoreCase) ||
                                             storeTypeNameBase.Equals(_nvarchar.StoreTypeNameBase, StringComparison.OrdinalIgnoreCase));
                    var isFixedLength = mappingInfo.IsFixedLength == true;
                    var charset       = isNationalCharSet ? _options.NationalCharSet : _options.CharSet;
                    var isUnicode     = mappingInfo.IsUnicode ?? charset.IsUnicode;
                    var bytesPerChar  = charset.MaxBytesPerChar;
                    var charSetSuffix = string.Empty;

                    if (isUnicode &&
                        (mappingInfo.IsKeyOrIndex &&
                         (_options.CharSetBehavior & CharSetBehavior.AppendToUnicodeIndexAndKeyColumns) != 0 ||
                         !mappingInfo.IsKeyOrIndex &&
                         (_options.CharSetBehavior & CharSetBehavior.AppendToUnicodeNonIndexAndKeyColumns) != 0) ||
                        !isUnicode &&
                        (mappingInfo.IsKeyOrIndex &&
                         (_options.CharSetBehavior & CharSetBehavior.AppendToAnsiIndexAndKeyColumns) != 0 ||
                         !mappingInfo.IsKeyOrIndex &&
                         (_options.CharSetBehavior & CharSetBehavior.AppendToAnsiNonIndexAndKeyColumns) != 0))
                    {
                        charSetSuffix = $" CHARACTER SET {(isNationalCharSet ? _options.NationalCharSet : _options.CharSet).Name}";
                    }

                    var maxSize = 8000 / bytesPerChar;

                    var size = mappingInfo.Size ??
                               (mappingInfo.IsKeyOrIndex
                                // Allow to use at most half of the max key length, so at least 2 columns can fit
                                   ? Math.Min(_connectionInfo.ServerVersion.MaxKeyLength / (bytesPerChar * 2), 255)
                                   : (int?)null);
                    if (size > maxSize)
                    {
                        size = null;
                    }

                    var dbType = isUnicode
                        ? isFixedLength ? DbType.StringFixedLength : DbType.String
                        : isFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString;

                    return(new MySqlStringTypeMapping(
                               size == null
                            ? "longtext" + charSetSuffix
                            : (isNationalCharSet ? "n" : string.Empty) +
                               (isFixedLength ? "char(" : "varchar(") + size + ")" + charSetSuffix,
                               dbType,
                               _options,
                               isUnicode,
                               size,
                               isFixedLength));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_connectionInfo.ServerVersion.SupportsDateTime6
                            ? _binaryRowVersion6
                            : _binaryRowVersion);
                    }

                    var size = mappingInfo.Size ??
                               (mappingInfo.IsKeyOrIndex ? _connectionInfo.ServerVersion.MaxKeyLength : (int?)null);

                    return(new MySqlByteArrayTypeMapping(
                               size: size,
                               fixedLength: mappingInfo.IsFixedLength == true));
                }

                if (_scaffoldingClrTypeMappings.TryGetValue(clrType, out mapping))
                {
                    return(mapping);
                }
            }

            return(null);
        }
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                if (clrType == typeof(float) &&
                    mappingInfo.Size != null &&
                    mappingInfo.Size <= 24 &&
                    (storeTypeNameBase.Equals("float", StringComparison.OrdinalIgnoreCase) ||
                     storeTypeNameBase.Equals("double precision", StringComparison.OrdinalIgnoreCase)))
                {
                    return(_real);
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (_namedClrMappings.TryGetValue(clrType.FullName, out var mappingFunc))
                {
                    return(mappingFunc(clrType));
                }

                if (clrType == typeof(string))
                {
                    var isAnsi        = mappingInfo.IsUnicode == false;
                    var isFixedLength = mappingInfo.IsFixedLength == true;
                    var baseName      = (isAnsi ? "" : "n") + (isFixedLength ? "char" : "varchar");
                    var maxSize       = isAnsi ? 8000 : 4000;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)(isAnsi ? 900 : 450) : null);
                    if (size > maxSize)
                    {
                        size = null;
                    }

                    var dbType = isAnsi
                        ? (isFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString)
                        : (isFixedLength ? DbType.StringFixedLength : (DbType?)null);

                    return(new SqlServerStringTypeMapping(
                               baseName + "(" + (size == null ? "max" : size.ToString()) + ")",
                               dbType,
                               !isAnsi,
                               size,
                               isFixedLength));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_rowversion);
                    }

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)900 : null);
                    if (size > 8000)
                    {
                        size = null;
                    }

                    var isFixedLength = mappingInfo.IsFixedLength == true;

                    return(new SqlServerByteArrayTypeMapping(
                               (isFixedLength ? "binary(" : "varbinary(") + (size == null ? "max" : size.ToString()) + ")",
                               DbType.Binary,
                               size));
                }
            }

            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            if (storeTypeName != null)
            {
                // If the TEXT store type is used with a size argument like `TEXT(n)`, it is handled as a synonym
                // for `VARCHAR(n)`.
                // If the TEXT store type is used without a size argument like `TEXT`, it is handled as a synonym
                // for `LONGCHAR`.
                // See "Notes" in: https://support.office.com/en-us/article/equivalent-ansi-sql-data-types-7a0a6bef-ef25-45f9-8a9a-3c5f21b5c65d
                if (storeTypeNameBase.Equals("text", StringComparison.OrdinalIgnoreCase) &&
                    !mappingInfo.IsFixedLength.GetValueOrDefault())
                {
                    return(mappingInfo.Size.GetValueOrDefault() > 0
                        ? _variableLengthUnicodeString
                        : _unboundedUnicodeString);
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (clrType == typeof(string))
                {
                    var isFixedLength = mappingInfo.IsFixedLength == true;

                    const int maxCharColumnSize        = 255;
                    const int maxIndexedCharColumnSize = 255;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)maxIndexedCharColumnSize : null);
                    if (size > maxCharColumnSize)
                    {
                        size = isFixedLength ? maxCharColumnSize : (int?)null;
                    }

                    return(size == null
                        ? _unboundedUnicodeString
                        : new JetStringTypeMapping(
                               storeType: isFixedLength
                                ? _fixedLengthUnicodeString.StoreTypeNameBase
                                : _variableLengthUnicodeString.StoreTypeNameBase,
                               size: size,
                               unicode: true));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_rowversion);
                    }

                    var isFixedLength = mappingInfo.IsFixedLength == true;

                    const int maxBinaryColumnSize = 510;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)maxBinaryColumnSize : null);
                    if (size > maxBinaryColumnSize)
                    {
                        size = isFixedLength ? maxBinaryColumnSize : (int?)null;
                    }

                    return(size == null
                        ? _unboundedBinary
                        : new JetByteArrayTypeMapping(
                               size: size,
                               storeType: isFixedLength
                                ? _fixedLengthBinary.StoreTypeNameBase
                                : _variableLengthBinary.StoreTypeNameBase));
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo)
        {
            var clrType           = mappingInfo.ClrType;
            var storeTypeName     = mappingInfo.StoreTypeName;
            var storeTypeNameBase = mappingInfo.StoreTypeNameBase;

            // Fixes: #22
            //clrType = clrType.UnwrapNullableType().UnwrapEnumType();


            if (storeTypeName != null)
            {
                if (clrType == typeof(float) &&
                    mappingInfo.Size != null &&
                    mappingInfo.Size <= 24 &&
                    (storeTypeNameBase.Equals("float", StringComparison.OrdinalIgnoreCase) ||
                     storeTypeNameBase.Equals("double precision", StringComparison.OrdinalIgnoreCase)))
                {
                    return(_real);
                }

                if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) ||
                    _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
                {
                    return(clrType == null ||
                           mapping.ClrType == clrType
                        ? mapping
                        : null);
                }
            }

            if (clrType != null)
            {
                if (_clrTypeMappings.TryGetValue(clrType, out var mapping))
                {
                    return(mapping);
                }

                if (clrType == typeof(string))
                {
                    bool isAnsi        = mappingInfo.IsUnicode == false;
                    bool isFixedLength = mappingInfo.IsFixedLength == true;
                    int  maxSize       = 255;

                    int?size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)255 : null);
                    if (size > maxSize)
                    {
                        size = isFixedLength ? maxSize : (int?)null;
                    }

                    return(size == null
                        ? isAnsi ? _unboundedAnsiString : _unboundedUnicodeString
                        : new JetStringTypeMapping(storeType: isFixedLength ? "char" : "varchar", size: size, unicode: true));
                }

                if (clrType == typeof(byte[]))
                {
                    if (mappingInfo.IsRowVersion == true)
                    {
                        return(_rowversion);
                    }

                    var isFixedLength = mappingInfo.IsFixedLength == true;

                    var size = mappingInfo.Size ?? (mappingInfo.IsKeyOrIndex ? (int?)510 : null);
                    if (size > 510)
                    {
                        size = isFixedLength ? 510 : (int?)null;
                    }

                    return(size == null
                        ? _unboundedBinary
                        : new JetByteArrayTypeMapping(size: size, storeType: isFixedLength ? "binary": "varbinary"));
                }
            }

            return(null);
        }