Skip to content

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

Open
@oskarb

Description

@oskarb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions