You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add type mapping support for additional store type postfix #11896
MySQL specifies the store type for an Unicode string in this manner: "VARCHAR(20) CHARACTER SET utf8" which is currently not supported by RelationalTypeMapping.
Instead of computing the store type in the constructor we should do it in a virtual method to allow it to be extended for other special cases like "varchar(max)"
Did a bit of investigations into collations on PostgreSQL.
MySQL specifies the store type for an Unicode string in this manner: "VARCHAR(20) CHARACTER SET utf8" which is currently not supported by RelationalTypeMapping.
CREATETABLEtest1 (
a text COLLATE "de_DE",
b text COLLATE "es_ES",
...
);
However, COLLATE is part of the column definition spec and not part of the type name, as the following doesn't work:
SELECT CAST('hello'AStext COLLATE 'en_US');
In that sense it's similar to NULL/NOT NULL, or DEFAULT. As a result, at least for PostgreSQL it seems to make more sense to have this as a standard migrations-only annotation rather than to make it part of the type mapping. The situation in MySQL may be similar or not (/cc @lauxjpn).
@lauxjpn We discussed this issue today and decided based on @roji's latest work on collation that Npgsql no longer needs us to do anything here. Is this something that is still needed for MySQL?
SELECTCONVERT('test', CHAR CHARACTER SET utf8mb4);
SELECT CAST('test'ASCHAR CHARACTER SET utf8mb4);
However, we also went the migrations annotation route and implemented HasCharSet() and HasCollation() extension methods for EF Core 3.0+, that can be used to set corresponding annotations (currently only on a column level, but table and database levels will be added for .NET 5).
We have planned to make the current behavior of adding the default char set and collation in our RelationalTypeMappingSource implementation obsolete and removing it for .NET 5.
So as far as I can see, we have no reservations against closing this issue.
If extending RelationalTypeMapping in a provider specific way is a route that needs to be taken in the future, a general approach like enabling the possibility to add annotations to it could be a viable way.
But of course providers are already implementing their concrete RelationalTypeMapping derived types, so they could just implement some provider specific interface in accordance with their requirements.
It might still come in handy though in the future, to give RelationalTypeMappingSource.FindMapping() (read) access through RelationalTypeMappingInfo to the annotations of the property for which the RelationalTypeMapping is currently requested.
However, we currently don't have a concrete scenario for this anymore for Pomelo.
Activity
AndriySvyryd commentedon May 4, 2018
Instead of computing the store type in the constructor we should do it in a virtual method to allow it to be extended for other special cases like "varchar(max)"
ajcvickers commentedon May 4, 2018
It would be good to consider allowing more general modifiers, such as those use for collations.
roji commentedon Jun 20, 2018
Another relevant and similar case: PostgreSQL allows
TIMESTAMP(5) WITH TIME ZONE, where the parentheses define the precision...20 remaining items
ajcvickers commentedon Feb 10, 2020
Also see high-level collations issue #19866
roji commentedon Mar 27, 2020
Did a bit of investigations into collations on PostgreSQL.
PostgreSQL supports something that looks similar:
However,
COLLATEis part of the column definition spec and not part of the type name, as the following doesn't work:In that sense it's similar to NULL/NOT NULL, or DEFAULT. As a result, at least for PostgreSQL it seems to make more sense to have this as a standard migrations-only annotation rather than to make it part of the type mapping. The situation in MySQL may be similar or not (/cc @lauxjpn).
AndriySvyryd commentedon Mar 27, 2020
@roji I agree. Was that the last thing you were going to do for this issue?
ajcvickers commentedon Mar 30, 2020
@lauxjpn We discussed this issue today and decided based on @roji's latest work on collation that Npgsql no longer needs us to do anything here. Is this something that is still needed for MySQL?
lauxjpn commentedon Mar 31, 2020
For MySQL, the following statements are valid:
However, we also went the migrations annotation route and implemented
HasCharSet()andHasCollation()extension methods for EF Core 3.0+, that can be used to set corresponding annotations (currently only on a column level, but table and database levels will be added for .NET 5).We have planned to make the current behavior of adding the default char set and collation in our
RelationalTypeMappingSourceimplementation obsolete and removing it for .NET 5.So as far as I can see, we have no reservations against closing this issue.
If extending
RelationalTypeMappingin a provider specific way is a route that needs to be taken in the future, a general approach like enabling the possibility to add annotations to it could be a viable way.But of course providers are already implementing their concrete
RelationalTypeMappingderived types, so they could just implement some provider specific interface in accordance with their requirements.It might still come in handy though in the future, to give
RelationalTypeMappingSource.FindMapping()(read) access throughRelationalTypeMappingInfoto the annotations of the property for which theRelationalTypeMappingis currently requested.However, we currently don't have a concrete scenario for this anymore for Pomelo.
ajcvickers commentedon Mar 31, 2020
Thanks @lauxjpn. Closing for now.