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
Remove SqlServer TypeMapping for CLR type char #8656
An EntityType with property char is not supported by the SQL Server provider. However SqlServerTypeMapper does have a mapping in _clrTypeMappings for char (mapping it to a SQL Server int column).
The reason for this is to support generation of single character literals in the Query Pipeline e.g. as arguments to functions, or LIKE can take an ESCAPE argument which is a single character - see this test. Query checks that it can interpret each argument (in this case a single character) - if it fails to find a type mapping for that type then it assumes it cannot generate literals for that type.
We should remove the entry in _clrTypeMappings for SqlServerTypeMapper for char so that we will generate the correct error if someone tries to create a property of that type. But we need to provide an alternate means to translate the literal above. We discussed:
Just changing how we deal with LIKE to enforce that the ESCAPE argument is a string, or
Changing the way Query treats arguments in general to specifically allow it to try a string TypeMapping if a char one does not exist.
Updating the TypeMapper to allow a set of types which it can interpret for generation of literals even if it does not allow that type as a property type.
GetChar is not supported in either SQL Server or Oracle's ADO.NET provider
Currently it is necessary for the provider to know how to generate a parameter, and not just a literal for the escapeCharacter argument.
Another potential approach (similar to # 2 above, but more generalized) would be to create some sort of fallback mapping mechanism for types like char and byte:
if char is not explicitly supported by the provider, it could fall back to a 'string' of size 1
if byte is not explicitly supported by the provider, it could fall back to a byte[] of size 1
This feels like it is slowly turning into a short-range version of the type conversions feature, but maybe that is ok.
Note: decided for preview2 to just to update the way we deal with LIKE to pass in the single character as a string. And remove the char SQL Server TypeMapping.
@ajcvickers@divega@anpete@smitpatel I thought the solution to just change the LIKE treatment was for preview2 only and that we wanted to discuss further on how, in general, to treat e.g. DbFunctions which had char parameters, or the issues that @divega raised above, for 2.0.0. So in short I thought we would be moving this to the 2.0.0 milestone but keeping it open.
I'll move it out of a milestone so we can re-triage. @divega Feel free to re-title/re-purpose this issue to cover the type conversion work we talked about, or open a new issue if that's better, or just combine the work into #242.
Activity
divega commentedon Jun 1, 2017
Additional data points:
GetCharis not supported in either SQL Server or Oracle's ADO.NET providerCurrently it is necessary for the provider to know how to generate a parameter, and not just a literal for the
escapeCharacterargument.Another potential approach (similar to # 2 above, but more generalized) would be to create some sort of fallback mapping mechanism for types like
charandbyte:charis not explicitly supported by the provider, it could fall back to a 'string' of size 1byteis not explicitly supported by the provider, it could fall back to abyte[]of size 1This feels like it is slowly turning into a short-range version of the type conversions feature, but maybe that is ok.
lajones commentedon Jun 1, 2017
Note: this came out of the work for #8631.
divega commentedon Jun 1, 2017
cc @anpete
lajones commentedon Jun 1, 2017
Note: decided for preview2 to just to update the way we deal with
LIKEto pass in the single character as a string. And remove thecharSQL Server TypeMapping.ajcvickers commentedon Jun 2, 2017
@lajones Can this issue be closed?
lajones commentedon Jun 2, 2017
@ajcvickers @divega @anpete @smitpatel I thought the solution to just change the
LIKEtreatment was for preview2 only and that we wanted to discuss further on how, in general, to treat e.g. DbFunctions which hadcharparameters, or the issues that @divega raised above, for 2.0.0. So in short I thought we would be moving this to the 2.0.0 milestone but keeping it open.ajcvickers commentedon Jun 2, 2017
I'll move it out of a milestone so we can re-triage. @divega Feel free to re-title/re-purpose this issue to cover the type conversion work we talked about, or open a new issue if that's better, or just combine the work into #242.
divega commentedon Jun 3, 2017
I have added text in #242 which I think covers the follow up for this (@ajcvickers feel free to review it). Closing for now.