Skip to content

Wrong GUID to string conversion when not explicitly referencing the id property #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oskarb opened this issue Apr 9, 2019 · 2 comments
Labels

Comments

@oskarb
Copy link
Member

oskarb commented Apr 9, 2019

Tested on SQLite with NH 5.2.5. (Update 2019-04-22: Also affects Firebird, MySQL and Oracle.)

With an entity where Id is Guid.

Consider these two queries:

List<string> guidDbStringsExplicitId =
    session.Query<Entity>().Select(e => e.Id.ToString()).ToList();

List<string> guidDbStringsImplicitId =
    session.Query<Entity>().Select(e => e.ToString()).ToList();

Both will aim to return the Id property, converted to string by the database engine, but the Id property is only explicitly referenced in one of them.

For guidDbStringsExplicitId, the generated SQL will be something like:

select
        substr(hex(entity0_.Id),
        7,
        2) || substr(hex(entity0_.Id),
        5,
        [...]
from
        Entity entity0_

While for guidDbStringsImplicitId is will be:

select
        cast(entity0_.Id as char) as col_0_0_ 
from
        Entity entity0_

The returned value is different. The expectation is that the SQL should be the same, or at least be functionally equivalent.

@oskarb
Copy link
Member Author

oskarb commented Apr 9, 2019

Related to PR #1856 and issue #1151.

@oskarb
Copy link
Member Author

oskarb commented Apr 9, 2019

PR #2111 contains a disabled test case that exposes this problem.

oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 14, 2019
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 14, 2019
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 14, 2019
…).

The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
@oskarb oskarb changed the title Different GUID to string conversion when not explicitly referencing the id property Wrong GUID to string conversion when not explicitly referencing the id property Apr 22, 2019
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 22, 2019
…).

The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 22, 2019
…).

The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 22, 2019
…).

The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
oskarb added a commit to oskarb/nhibernate-core that referenced this issue Apr 23, 2019
…).

The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
fredericDelaporte pushed a commit that referenced this issue Aug 24, 2019
* Add helper methods to get the configured connection string
* Expand NH-3426 tests to expose GH-2110 (and GH-2109)
* Detect BinaryGuid setting and apply correct GUID-to-string expression
* Document the new sqlite.binaryguid setting

BinaryGuid is a configuration property of some MySql drivers, but relates to type used in the database for handling GUIDs, which impacts the dialect.

The cases for GH-2109 are marked as ignored for now, as that is not a regression.

Fixes #2110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant