diff --git a/src/NHibernate.Test/Async/NHSpecificTest/NH3426/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/NH3426/Fixture.cs index cb86ae55216..c48782508bb 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/NH3426/Fixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/NH3426/Fixture.cs @@ -97,5 +97,18 @@ public async Task CompareStringColumnWithGuidToStringAsync() Assert.That(list, Has.Count.EqualTo(0)); } } + + [Test] + public async Task CompareStringColumnWithNullableGuidToStringAsync() + { + using (var session = OpenSession()) + { + var list = await (session.Query() + .Where(x => ((Guid?) x.Id).ToString() == x.Id.ToString()) + .ToListAsync()); + + Assert.That(list, Has.Count.EqualTo(1)); + } + } } } diff --git a/src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs index 04ffc0fdb6b..6bf273f93da 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs @@ -85,5 +85,18 @@ public void CompareStringColumnWithGuidToString() Assert.That(list, Has.Count.EqualTo(0)); } } + + [Test] + public void CompareStringColumnWithNullableGuidToString() + { + using (var session = OpenSession()) + { + var list = session.Query() + .Where(x => ((Guid?) x.Id).ToString() == x.Id.ToString()) + .ToList(); + + Assert.That(list, Has.Count.EqualTo(1)); + } + } } } diff --git a/src/NHibernate/Linq/Functions/StringGenerator.cs b/src/NHibernate/Linq/Functions/StringGenerator.cs index 02cf535951f..2d93f6c85bf 100644 --- a/src/NHibernate/Linq/Functions/StringGenerator.cs +++ b/src/NHibernate/Linq/Functions/StringGenerator.cs @@ -317,21 +317,15 @@ public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) public class ToStringHqlGeneratorForMethod : IHqlGeneratorForMethod { - private static readonly System.Type _guidType = typeof(Guid); - - public IEnumerable SupportedMethods - { - get { throw new NotSupportedException(); } - } + public IEnumerable SupportedMethods => throw new NotSupportedException(); public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { - if (targetObject.Type == _guidType) - { - return treeBuilder.MethodCall("strguid", visitor.Visit(targetObject).AsExpression()); - } + var methodName = targetObject.Type == typeof(Guid) || targetObject.Type == typeof(Guid?) + ? "strguid" + : "str"; - return treeBuilder.MethodCall("str", visitor.Visit(targetObject).AsExpression()); + return treeBuilder.MethodCall(methodName, visitor.Visit(targetObject).AsExpression()); } } }