protected void Initialize()
        {
            //
            // String mappings depend on the MySqlOptions.NoBackslashEscapes setting:
            //

            _charUnicode       = new MySqlStringTypeMapping("char", DbType.StringFixedLength, _options, unicode: true, fixedLength: true);
            _varcharUnicode    = new MySqlStringTypeMapping("varchar", DbType.String, _options, unicode: true);
            _varcharmaxUnicode = new MySqlStringTypeMapping("longtext", DbType.String, _options, unicode: true);

            _nchar    = new MySqlStringTypeMapping("nchar", DbType.StringFixedLength, _options, unicode: true, fixedLength: true);
            _nvarchar = new MySqlStringTypeMapping("nvarchar", DbType.String, _options, unicode: true);

            _enum = new MySqlStringTypeMapping("enum", DbType.String, _options, unicode: true);

            _guid = null;

            _storeTypeMappings
                = new Dictionary <string, RelationalTypeMapping>(StringComparer.OrdinalIgnoreCase)
                {
                // bit
                { "bit", _bit },

                // integers
                { "tinyint", _tinyint },
                { "tinyint unsigned", _utinyint },
                { "smallint", _smallint },
                { "smallint unsigned", _usmallint },
                { "mediumint", _int },
                { "mediumint unsigned", _uint },
                { "int", _int },
                { "int unsigned", _uint },
                { "integer", _int },
                { "integer unsigned", _uint },
                { "bigint", _bigint },
                { "bigint unsigned", _ubigint },

                // decimals
                { "decimal", _decimal },
                { "decimal unsigned", _decimal },         // deprecated since 8.0.17-mysql
                { "numeric", _decimal },
                { "numeric unsigned", _decimal },         // deprecated since 8.0.17-mysql
                { "dec", _decimal },
                { "dec unsigned", _decimal },             // deprecated since 8.0.17-mysql
                { "fixed", _decimal },
                { "fixed unsigned", _decimal },           // deprecated since 8.0.17-mysql
                { "double", _double },
                { "double unsigned", _double },           // deprecated since 8.0.17-mysql
                { "double precision", _double },
                { "double precision unsigned", _double }, // deprecated since 8.0.17-mysql
                { "real", _double },
                { "real unsigned", _double },             // deprecated since 8.0.17-mysql
                { "float", _float },
                { "float unsigned", _float },             // deprecated since 8.0.17-mysql

                // binary
                { "binary", _binary },
                { "varbinary", _varbinary },
                { "tinyblob", _varbinary },
                { "blob", _varbinary },
                { "mediumblob", _varbinary },
                { "longblob", _varbinary },

                // string
                { "char", _charUnicode },
                { "varchar", _varcharUnicode },
                { "tinytext", _varcharmaxUnicode },
                { "text", _varcharmaxUnicode },
                { "mediumtext", _varcharmaxUnicode },
                { "longtext", _varcharmaxUnicode },

                { "enum", _enum },

                { "nchar", _nchar },
                { "nvarchar", _nvarchar },

                // DateTime
                { "date", _date }
                };

            _clrTypeMappings
                = new Dictionary <Type, RelationalTypeMapping>
                {
                // integers
                { typeof(short), _smallint },
                { typeof(ushort), _usmallint },
                { typeof(int), _int },
                { typeof(uint), _uint },
                { typeof(long), _bigint },
                { typeof(ulong), _ubigint },

                // decimals
                { typeof(decimal), _decimal },
                { typeof(float), _float },
                { typeof(double), _double },

                // byte / char
                { typeof(sbyte), _tinyint },
                { typeof(byte), _utinyint },
                };

            // Boolean
            if (_options.DefaultDataTypeMappings.ClrBoolean != MySqlBooleanType.None)
            {
                _clrTypeMappings[typeof(bool)] = _options.DefaultDataTypeMappings.ClrBoolean == MySqlBooleanType.Bit1
                    ? _bit1
                    : _tinyint1;
            }

            // DateTime
            _storeTypeMappings["time"] = !_options.ServerVersion.SupportsDateTime6 ||
                                         _options.DefaultDataTypeMappings.ClrTimeSpan == MySqlTimeSpanType.Time
                ? _time
                : _time6;

            _clrTypeMappings[typeof(TimeSpan)] = !_options.ServerVersion.SupportsDateTime6 ||
                                                 _options.DefaultDataTypeMappings.ClrTimeSpan == MySqlTimeSpanType.Time
                ? _time
                : _time6;

            _clrTypeMappings[typeof(DateTime)] = !_options.ServerVersion.SupportsDateTime6 ||
                                                 _options.DefaultDataTypeMappings.ClrDateTime == MySqlDateTimeType.DateTime
                ? _dateTime
                : _options.DefaultDataTypeMappings.ClrDateTime == MySqlDateTimeType.Timestamp6
                    ? _timeStamp6
                    : _dateTime6;

            _clrTypeMappings[typeof(DateTimeOffset)] = !_options.ServerVersion.SupportsDateTime6 ||
                                                       _options.DefaultDataTypeMappings.ClrDateTime == MySqlDateTimeType.DateTime
                ? _dateTimeOffset
                : _options.DefaultDataTypeMappings.ClrDateTimeOffset == MySqlDateTimeType.Timestamp6
                    ? _timeStampOffset6
                    : _dateTimeOffset6;

            // Guid
            if (_guid != null)
            {
                _clrTypeMappings[typeof(Guid)] = _guid;
            }

            // Type mappings that only exist to work around the limited code generation capabilites when scaffolding:
            _scaffoldingClrTypeMappings = new Dictionary <Type, RelationalTypeMapping>
            {
                { typeof(MySqlCodeGenerationMemberAccess), _codeGenerationMemberAccess }
            };
        }
        private void Initialize()
        {
            //
            // String mappings depend on the MySqlOptions.NoBackslashEscapes setting:
            //

            _charUnicode       = new MySqlStringTypeMapping("char", DbType.StringFixedLength, _options, fixedLength: true);
            _varcharUnicode    = new MySqlStringTypeMapping("varchar", DbType.String, _options);
            _tinytextUnicode   = new MySqlStringTypeMapping("tinytext", DbType.String, _options);
            _textUnicode       = new MySqlStringTypeMapping("text", DbType.String, _options);
            _mediumtextUnicode = new MySqlStringTypeMapping("mediumtext", DbType.String, _options);
            _longtextUnicode   = new MySqlStringTypeMapping("longtext", DbType.String, _options);

            _nchar    = new MySqlStringTypeMapping("nchar", DbType.StringFixedLength, _options, fixedLength: true);
            _nvarchar = new MySqlStringTypeMapping("nvarchar", DbType.String, _options);

            _enum = new MySqlStringTypeMapping("enum", DbType.String, _options);

            _guid = MySqlGuidTypeMapping.IsValidGuidFormat(_options.ConnectionSettings.GuidFormat)
                ? new MySqlGuidTypeMapping(_options.ConnectionSettings.GuidFormat)
                : null;

            _storeTypeMappings
                = new Dictionary <string, RelationalTypeMapping[]>(StringComparer.OrdinalIgnoreCase)
                {
                // bit
                { "bit", new[] { _bit } },

                // integers
                { "tinyint", new[] { _tinyint } },
                { "tinyint unsigned", new[] { _utinyint } },
                { "smallint", new[] { _smallint } },
                { "smallint unsigned", new[] { _usmallint } },
                { "mediumint", new[] { _int } },
                { "mediumint unsigned", new[] { _uint } },
                { "int", new[] { _int } },
                { "int unsigned", new[] { _uint } },
                { "integer", new[] { _int } },
                { "integer unsigned", new[] { _uint } },
                { "bigint", new[] { _bigint } },
                { "bigint unsigned", new[] { _ubigint } },

                // decimals
                { "decimal", new[] { _decimal } },
                { "decimal unsigned", new[] { _decimal } },            // deprecated since 8.0.17-mysql
                { "numeric", new[] { _decimal } },
                { "numeric unsigned", new[] { _decimal } },            // deprecated since 8.0.17-mysql
                { "dec", new[] { _decimal } },
                { "dec unsigned", new[] { _decimal } },                // deprecated since 8.0.17-mysql
                { "fixed", new[] { _decimal } },
                { "fixed unsigned", new[] { _decimal } },              // deprecated since 8.0.17-mysql
                { "double", new[] { _double } },
                { "double unsigned", new[] { _double } },              // deprecated since 8.0.17-mysql
                { "double precision", new[] { _double } },
                { "double precision unsigned", new[] { _double } },    // deprecated since 8.0.17-mysql
                { "real", new[] { _double } },
                { "real unsigned", new[] { _double } },                // deprecated since 8.0.17-mysql
                { "float", new[] { _float } },
                { "float unsigned", new[] { _float } },                // deprecated since 8.0.17-mysql

                // binary
                { "binary", new[] { _binary } },
                { "varbinary", new[] { _varbinary } },
                { "tinyblob", new[] { _varbinary } },
                { "blob", new[] { _varbinary } },
                { "mediumblob", new[] { _varbinary } },
                { "longblob", new[] { _varbinary } },

                // string
                { "char", new[] { _charUnicode } },
                { "varchar", new[] { _varcharUnicode } },
                { "tinytext", new[] { _tinytextUnicode } },
                { "text", new[] { _textUnicode } },
                { "mediumtext", new[] { _mediumtextUnicode } },
                { "longtext", new[] { _longtextUnicode } },

                { "enum", new[] { _enum } },

                { "nchar", new[] { _nchar } },
                { "nvarchar", new[] { _nvarchar } },

                // DateTime
                { "year", new[] { _year } },
                { "date", new[] { _date } },
                { "time", new[] { _time } },
                { "datetime", new RelationalTypeMapping[] { _dateTime, _dateTimeOffset } },
                { "timestamp", new RelationalTypeMapping[] { _timeStamp, _timeStampOffset } },
                };

            _clrTypeMappings
                = new Dictionary <Type, RelationalTypeMapping>
                {
                // integers
                { typeof(short), _smallint },
示例#3
0
        protected void Initialize()
        {
            //
            // String mappings depend on the MySqlOptions.NoBackslashEscapes setting:
            //

            _charUnicode       = new MySqlStringTypeMapping("char", DbType.StringFixedLength, _options, unicode: true, fixedLength: true);
            _varcharUnicode    = new MySqlStringTypeMapping("varchar", DbType.String, _options, unicode: true);
            _varcharmaxUnicode = new MySqlStringTypeMapping("longtext", DbType.String, _options, unicode: true);

            _nchar    = new MySqlStringTypeMapping("nchar", DbType.StringFixedLength, _options, unicode: true, fixedLength: true);
            _nvarchar = new MySqlStringTypeMapping("nvarchar", DbType.String, _options, unicode: true);

            _enum = new MySqlStringTypeMapping("enum", DbType.String, _options, unicode: true);

            _storeTypeMappings
                = new Dictionary <string, RelationalTypeMapping>(StringComparer.OrdinalIgnoreCase)
                {
                // bit
                { "bit", _bit },

                // integers
                { "tinyint", _tinyint },
                { "tinyint unsigned", _utinyint },
                { "smallint", _smallint },
                { "smallint unsigned", _usmallint },
                { "mediumint", _int },
                { "mediumint unsigned", _uint },
                { "int", _int },
                { "int unsigned", _uint },
                { "bigint", _bigint },
                { "bigint unsigned", _ubigint },

                // decimals
                { "decimal", _decimal },
                { "dec", _decimal },
                { "fixed", _decimal },
                { "double", _double },
                { "double precision", _double },
                { "real", _double },
                { "float", _float },

                // binary
                { "binary", _binary },
                { "varbinary", _varbinary },
                { "tinyblob", _varbinary },
                { "blob", _varbinary },
                { "mediumblob", _varbinary },
                { "longblob", _varbinary },

                // string
                { "char", _charUnicode },
                { "varchar", _varcharUnicode },
                { "tinytext", _varcharmaxUnicode },
                { "text", _varcharmaxUnicode },
                { "mediumtext", _varcharmaxUnicode },
                { "longtext", _varcharmaxUnicode },

                { "enum", _enum },

                { "nchar", _nchar },
                { "nvarchar", _nvarchar },

                // DateTime
                { "date", _date }
                };

            _clrTypeMappings
                = new Dictionary <Type, RelationalTypeMapping>
                {
                // integers
                { typeof(short), _smallint },
                { typeof(ushort), _usmallint },
                { typeof(int), _int },
                { typeof(uint), _uint },
                { typeof(long), _bigint },
                { typeof(ulong), _ubigint },

                // decimals
                { typeof(decimal), _decimal },
                { typeof(float), _float },
                { typeof(double), _double },

                // byte / char
                { typeof(sbyte), _tinyint },
                { typeof(byte), _utinyint }
                };

            // Boolean
            _clrTypeMappings[typeof(bool)] = _options.ConnectionSettings.TreatTinyAsBoolean
                ? _tinyint1
                : _bit1;

            // Guid
            _clrTypeMappings[typeof(Guid)] = _options.ConnectionSettings.OldGuids
                ? _oldGuid
                : _uniqueidentifier;

            // DateTime
            if (_connectionInfo.ServerVersion.SupportsDateTime6)
            {
                _storeTypeMappings["time"]               = _time6;
                _clrTypeMappings[typeof(DateTime)]       = _dateTime6;
                _clrTypeMappings[typeof(DateTimeOffset)] = _dateTimeOffset6;
                _clrTypeMappings[typeof(TimeSpan)]       = _time6;
            }
            else
            {
                _storeTypeMappings["time"]               = _time;
                _clrTypeMappings[typeof(DateTime)]       = _dateTime;
                _clrTypeMappings[typeof(DateTimeOffset)] = _dateTimeOffset;
                _clrTypeMappings[typeof(TimeSpan)]       = _time;
            }
        }