Skip to content
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

Query: DbSet may not be EntityQueryable #11043

Closed
smitpatel opened this issue Feb 22, 2018 · 0 comments
Closed

Query: DbSet may not be EntityQueryable #11043

smitpatel opened this issue Feb 22, 2018 · 0 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Member

smitpatel commented Feb 22, 2018

In test

public void Non_generic_ExecuteQuery_does_not_throw()
        {
            var context = new TestContext();
            Func<IQueryable<TestEntity>, int> func = Queryable.Count;
            IQueryable q = context.TestEntities;
            var expr = Expression.Call(null, func.GetMethodInfo(), Expression.Constant(q));
            Assert.Equal(0, q.Provider.Execute<int>(expr));
            Assert.Equal(0, (int)q.Provider.Execute(expr));
        }

Here the ConstantExpression generated for context.TestEntities is not an EntityQueryable. WIth optimization going in #11030 we now try to parametrize all queryables which not EntityQueryable, which cause this test to fail with A second operation started error.

After discussing with @ajcvickers

  • Is it possible to have DbSet type without being of EntityQueryable type?
    • Yes => Then we need to pattern match exclude this case from being funcletized.
    • No => Then we need to fix so that query starting from DbSet already creates EntityQueryable inside Expression tree.
smitpatel added a commit that referenced this issue Feb 23, 2018
Issue: A linq query starting from DbSet always has EntityQueryable. But for a manually created query incorrectly passes Constant(IQueryable) rather than IQueryable.Expression then we try to parametrize it and cause multiple running queries.
The fix is to not funcletize it. The Constant(DbSet) gets converted to EntityQueryable during ReLinq query parsing.
This is a negative case. The query is malformed. We would leak context instance in this case. Since it is hot path, we are not going to add overhead for all other cases.

Resolves #11043
smitpatel added a commit that referenced this issue Feb 23, 2018
Issue: A linq query starting from DbSet always has EntityQueryable. But for a manually created query incorrectly passes Constant(IQueryable) rather than IQueryable.Expression then we try to parametrize it and cause multiple running queries.
The fix is to not funcletize it. The Constant(DbSet) gets converted to EntityQueryable during ReLinq query parsing.
This is a negative case. The query is malformed. We would leak context instance in this case. Since it is hot path, we are not going to add overhead for all other cases.

Resolves #11043
smitpatel added a commit that referenced this issue Feb 23, 2018
Issue: A linq query starting from DbSet always has EntityQueryable. But for a manually created query incorrectly passes Constant(IQueryable) rather than IQueryable.Expression then we try to parametrize it and cause multiple running queries.
The fix is to not funcletize it. The Constant(DbSet) gets converted to EntityQueryable during ReLinq query parsing.
This is a negative case. The query is malformed. We would leak context instance in this case. Since it is hot path, we are not going to add overhead for all other cases.

Resolves #11043
smitpatel added a commit that referenced this issue Feb 23, 2018
Issue: A linq query starting from DbSet always has EntityQueryable. But for a manually created query incorrectly passes Constant(IQueryable) rather than IQueryable.Expression then we try to parametrize it and cause multiple running queries.
The fix is to not funcletize it. The Constant(DbSet) gets converted to EntityQueryable during ReLinq query parsing.
This is a negative case. The query is malformed. We would leak context instance in this case. Since it is hot path, we are not going to add overhead for all other cases.

Resolves #11043
smitpatel added a commit that referenced this issue Feb 23, 2018
Issue: A linq query starting from DbSet always has EntityQueryable. But for a manually created query incorrectly passes Constant(IQueryable) rather than IQueryable.Expression then we try to parametrize it and cause multiple running queries.
The fix is to not funcletize it. The Constant(DbSet) gets converted to EntityQueryable during ReLinq query parsing.
This is a negative case. The query is malformed. We would leak context instance in this case. Since it is hot path, we are not going to add overhead for all other cases.

Resolves #11043
@smitpatel smitpatel self-assigned this Feb 23, 2018
@smitpatel smitpatel added type-bug closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Feb 23, 2018
@smitpatel smitpatel added this to the 2.1.0 milestone Feb 23, 2018
@ajcvickers ajcvickers modified the milestones: 2.1.0-preview2, 2.1.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants