Skip to content

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

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

Closed
nhibernate-bot opened this issue Oct 13, 2017 · 3 comments

Comments

@nhibernate-bot
Copy link
Collaborator

nhibernate-bot commented Oct 13, 2017

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.

@fredericDelaporte
Copy link
Member

Very similar to #1363, but still not fixed while most cases of #1363 are.

fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 18, 2018
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 18, 2018
 * Fixes nhibernate#1330 (NH-3673)
 * Allow a workaround for nhibernate#1363 (NH-2500)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 18, 2018
 * Fixes nhibernate#1330 (NH-3673)
 * Allows a workaround for nhibernate#1363 (NH-2500)
fredericDelaporte added a commit that referenced this issue Jan 19, 2018
 * NH-2500 tests (#1363)
 * NH-3673 test (#1330)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 19, 2018
 * Fixes nhibernate#1330 (NH-3673)
 * Allows a workaround for nhibernate#1363 (NH-2500)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 19, 2018
 * Fixes nhibernate#1330
 * Fixes nhibernate#866
 * Fixes most of nhibernate#1363 (a workaround is still needed for one case)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 19, 2018
 * Fixes nhibernate#1330
 * Fixes nhibernate#866
 * Fixes most of nhibernate#1363 (a workaround is still needed for one case)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 19, 2018
 * Fixes nhibernate#1330 ( NH-3673 )
 * Obsoletes nhibernate#866 ( NH-2658 )
 * Fixes most of nhibernate#1363 (a workaround is still needed for one case; NH-2500 )
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 19, 2018
 * Fixes nhibernate#1330 (NH-3673)
 * Obsoletes nhibernate#866 (NH-2658)
 * Fixes most of nhibernate#1363 (a workaround is still needed for one case; NH-2500)
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 20, 2018
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Jan 20, 2018
fredericDelaporte added a commit that referenced this issue Jan 20, 2018
 * Fixes #1330 (NH-3673)
 * Obsoletes #866 (NH-2658)
 * Fixes #1363 (NH-2500)
@fredericDelaporte fredericDelaporte added this to the 5.1 milestone Jan 20, 2018
@jeremycampbellaustin
Copy link

I'm wondering if this issue has surfaced again in v5.3.0. v5.2.7 does not have the issue.

public SomeEntityDto Get(int id) { _session.Query<SomeEntity>() .Where(e => e.Id == id) .Select(e => new SomeEntityDto { Id = id, Year = e.ScholarYear }).Single(); }

The first time the query is called, the Id on the returned object is correct. After the first call, the Id on the returned object is always the id from the first call. The results coming back from the database looks correct, so it appears there is something going on with the hydration of SomeEntityDto.

@cremor
Copy link
Contributor

cremor commented Sep 4, 2020

@jeremycampbellaustin You might want to create a new issue for that. I'm not sure if the developers of NHibernate monitor old issues for comments.

edit: Ok, seems like they do 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants