-
Notifications
You must be signed in to change notification settings - Fork 165
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
NotSupportedException using ExpandableQuery as nested query #111
Comments
Is there any news on this? LINQKit making it impossible to compose Queryables is a pretty significant shortcoming, and the resulting error message is almost untracably misleading. |
This issue is also important for us, as we use LINQKit extensively in our project and there are a lot of shared methods returning expandable queries. Combining those queries in a single query via join, contains, etc. is currently very hard or impossible due to that issue. From what I found so far, the problem happens only in EF6. At some point of building a query it tries to retrieve Since it's neither an instance of My guess is that the fix should be somewhere in the |
Here's also a simple test case that can be added in [Fact]
public async Task DbAsync_ExpandNestedQueries()
{
Expression<Func<Entity, int>> getEntityValue = e => e.Value;
Expression<Func<RelatedEntity, int>> getRelatedEntityValue = e => e.Value;
var query1 = _db.Entities.AsExpandable().Select(e => getEntityValue.Invoke(e));
var query2 = _db.RelatedEntities.AsExpandable().Select(e => getRelatedEntityValue.Invoke(e));
var query =
from q1 in query1
from q2 in query2
select new { q1, q2 };
await query.ToListAsync();
} Please share your ideas for a workaround if any. |
Any known workarounds? |
@rgroenewoudt, post your exact query and which EF version do you use. This one should work. Issue has 4 years and probably should be closed. |
Using .NET 8 with Entity Framework 6.4.4 with LinqKit.EntityFramework 1.2.5 Example code:
The second AsExpandableEF() makes it fail with:
We have functions wrapping our IQueryable for extra filtering, we added AsExpandableEF() to it as adding it to every query manually is not doable but it results in queries with multiple AsExpandableEF() calls. |
Remove second @scottksmith95, I think it is not big deal to remove this call |
I have a number of library functions (QueryObjectAccess in this case) that perform filtering on a IQueryable, often involving PredicateBuilder. I don't want to forget to apply AsExpandable(), so I'm calling it inside these functions. Worst case up until now, AsExpandable() was a no-op that that returned the already expandable query.
I've recently added some features that use these filtered queries as criteria for other queries, for example:
This is causing a NotSupportedException: Unable to create a constant value of type 'Models.Product'. Only primitive types or enumeration types are supported in this context.
It seems like the ExpressionExpander could handle this, but doesn't appear to. Is there a better way to handle this?
If I change QueryObjectAccess() to call Expand on the expression instead, it works. Is that a better approach for something buried in a library?
(I realize that in case I could conditionally call AsExpandable on productQuery depending on how it was to be used, but I can't always do that)
The text was updated successfully, but these errors were encountered: