Skip to content

Evaluatable expressions with parameters are no more pre-evaluated #2458

@dbakuntsev

Description

@dbakuntsev

Tried with the git clone https://github.com/nhibernate/nhibernate-core.git branch.

The following mock-up code will not work:

Guid guid = Guid.Parse("2D7E6EB3-BD08-4A40-A4E7-5150F7895821");
session.Query<Entity>().Where(x => x.TextField.Contains($"VALUE {guid}"))

That is, NhRelinqQueryParser.PreTransform() instead of evaluating String.Format to its final form "VALUE 2D7E6EB3-BD08-4A40-A4E7-5150F7895821" will stop short and will yield Format("VALUE {0}", Convert("2D7E6EB3-BD08-4A40-A4E7-5150F7895821")) instead. Naturally, that will not be translated to any meaningful SQL later on and will result in an exception System.NotSupportedException: System.String Format(System.String, System.Object, System.Object).

A trivial workaround exists:

Guid guid = Guid.Parse("2D7E6EB3-BD08-4A40-A4E7-5150F7895821");
session.Query<Entity>().Where(x => x.TextField.Contains($"VALUE {guid.ToString()}"))

But it occurs to me that this is a bug, as the workaround shouldn't be required.

Furthermore, it is not obvious what's going on from looking at the final exception (so the workaround may be implemented).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions