Skip to content

Fix Linq failure on null parameter value #2836

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

Merged
merged 1 commit into from
Jun 28, 2021
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
15 changes: 15 additions & 0 deletions src/NHibernate.Test/Async/Linq/LinqQuerySamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using NHibernate.DomainModel.Northwind.Entities;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework;
using NHibernate.Linq;

Expand Down Expand Up @@ -1370,5 +1371,19 @@ from s2 in sup2.DefaultIfEmpty()
Assert.That(GetTotalOccurrences(sql, "left outer join"), Is.EqualTo(2));
}
}

[Test]
public void ReplaceFunctionWithNullArgumentAsync()
{
var query = from e in db.Employees
select e.FirstName.Replace(e.LastName, null);
List<string> results = null;
Assert.That(
async () =>
{
results = await (query.ToListAsync());
}, Throws.Nothing, "Expected REPLACE(FirstName, LastName, NULL) to be supported");
Assert.That(results, Is.Not.Null);
}
}
}
15 changes: 15 additions & 0 deletions src/NHibernate.Test/Linq/LinqQuerySamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using NHibernate.DomainModel.Northwind.Entities;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework;

namespace NHibernate.Test.Linq
Expand Down Expand Up @@ -1955,6 +1956,20 @@ public void DLinq2C()

Assert.That(!q.Any(orderid => withNullShippingDate.Contains(orderid)));
}

[Test]
public void ReplaceFunctionWithNullArgument()
{
var query = from e in db.Employees
select e.FirstName.Replace(e.LastName, null);
List<string> results = null;
Assert.That(
() =>
{
results = query.ToList();
}, Throws.Nothing, "Expected REPLACE(FirstName, LastName, NULL) to be supported");
Assert.That(results, Is.Not.Null);
}
}

public class ParentChildBatch<T, TKey, TSub>
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Linq/Visitors/ParameterTypeLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static IType GetParameterType(
return candidateType;
}

if (visitor.NotGuessableConstants.Contains(constantExpression))
if (visitor.NotGuessableConstants.Contains(constantExpression) && constantExpression.Value != null)
{
return null;
}
Expand Down