Closure variable values locked in from expressions in NHibernate LINQ provider
Description
The value of a closure variable used in a function call in an expression (ex. in Select) in the NHibernate LINQ provider gets locked in to the value that was present the first time the query gets evaluated.
Reproduction case:
class Repro
{
private Guid MyFunc(MyType item, Guid closureValue)
{
return closureValue;
}
public object Run()
{
IEnumerable<Guid> result;
var closureVariable = Guid.NewGuid();
using (var session = mySessionFactory.OpenSession())
{
result = session.Query<MyType>()
.Select(x => MyFunc(x, closureVariable))
.ToList();
}
Debug.Assert(result.First() == closureVariable); // Works the first time but fails all subsequent times
return result;
}
}
The value of a closure variable used in a function call in an expression (ex. in Select) in the NHibernate LINQ provider gets locked in to the value that was present the first time the query gets evaluated.
Reproduction case:
class Repro { private Guid MyFunc(MyType item, Guid closureValue) { return closureValue; } public object Run() { IEnumerable<Guid> result; var closureVariable = Guid.NewGuid(); using (var session = mySessionFactory.OpenSession()) { result = session.Query<MyType>() .Select(x => MyFunc(x, closureVariable)) .ToList(); } Debug.Assert(result.First() == closureVariable); // Works the first time but fails all subsequent times return result; } }