Skip to content

NH-3673 - Closure variable values locked in from expressions in NHibernate LINQ provider #1330

Closed
@nhibernate-bot

Description

@nhibernate-bot

David Straw created an issue — 22nd August 2014, 16:07:48:

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;
    }
}

Ricardo Peres added a comment — 22nd August 2014, 17:52:54:

Probably a duplicate of NH-2658.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions