Skip to content

Remove SqlServer TypeMapping for CLR type char #8656

Closed

Description

@lajones

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:

  1. Just changing how we deal with LIKE to enforce that the ESCAPE argument is a string, or
  2. Changing the way Query treats arguments in general to specifically allow it to try a string TypeMapping if a char one does not exist.
  3. 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.

Activity

  1. divega commented on Jun 1, 2017

    @divega
    Contributor

    Additional data points:

    • 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.

  2. lajones commented on Jun 1, 2017

    @lajones
    ContributorAuthor

    Note: this came out of the work for #8631.

  3. divega commented on Jun 1, 2017

    @divega
    Contributor
  4. self-assigned this
    on Jun 1, 2017
  5. added this to the milestone on Jun 1, 2017
  6. lajones commented on Jun 1, 2017

    @lajones
    ContributorAuthor

    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.

  7. ajcvickers commented on Jun 2, 2017

    @ajcvickers
    Contributor

    @lajones Can this issue be closed?

  8. lajones commented on Jun 2, 2017

    @lajones
    ContributorAuthor

    @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.

  9. ajcvickers commented on Jun 2, 2017

    @ajcvickers
    Contributor

    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.

  10. removed this from the milestone on Jun 2, 2017
  11. divega commented on Jun 3, 2017

    @divega
    Contributor

    I have added text in #242 which I think covers the follow up for this (@ajcvickers feel free to review it). Closing for now.

  12. added this to the milestone on Jun 3, 2017
  13. modified the milestones: , 2.0.0 on Oct 15, 2022
  14. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions