Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/NH3426/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>()
.Where(x => ((Guid?) x.Id).ToString() == x.Id.ToString())
.ToListAsync());

Assert.That(list, Has.Count.EqualTo(1));
}
}
}
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>()
.Where(x => ((Guid?) x.Id).ToString() == x.Id.ToString())
.ToList();

Assert.That(list, Has.Count.EqualTo(1));
}
}
}
}
16 changes: 5 additions & 11 deletions src/NHibernate/Linq/Functions/StringGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,15 @@ public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)

public class ToStringHqlGeneratorForMethod : IHqlGeneratorForMethod
{
private static readonly System.Type _guidType = typeof(Guid);

public IEnumerable<MethodInfo> SupportedMethods
{
get { throw new NotSupportedException(); }
}
public IEnumerable<MethodInfo> SupportedMethods => throw new NotSupportedException();

public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> 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());
}
}
}