You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Probably I'm doing something incorrect. Thanks in advance for reading this.
The issue
I need to check the same specific condition (where clause) many times.
I this condition changes I don't want to change all my queries. So I wanted to abstract this condition in a separate method.
public Expression<Func<Project, bool>> IsProjectVisibleForResearcher(string userId)
{
return p => p.Type == Enums.ProjectType.Open || p.Invites.Any(i => i.InviteeId == userId);
}
Exception
Exception message: Could not parse expression 'c.Projects.AsQueryable()': This overload of the method 'System.Linq.Queryable.AsQueryable' is currently not supported.
Stack trace:
at Remotion.Linq.Parsing.Structure.MethodCallExpressionParser.GetNodeType(MethodCallExpression expressionToParse)
at Remotion.Linq.Parsing.Structure.MethodCallExpressionParser.Parse(String associatedIdentifier, IExpressionNode source, IEnumerable`1 arguments, MethodCallExpression expressionToParse)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at System.Linq.Enumerable.SelectListPartitionIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Remotion.Linq.Parsing.Structure.MethodCallExpressionParser.Parse(String associatedIdentifier, IExpressionNode source, IEnumerable`1 arguments, MethodCallExpression expressionToParse)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_0`1.<CompileQuery>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Remotion.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at DAL.Repositories.CompanyRepository.GetAllAllowedCompanies(String userId) in E:\DAL\Repositories\CompanyRepository.cs:line 39
at BLL.Managers.CompanyManager.GetAllAlowedCompanies(ClaimsPrincipal user) in E:\src\BLL\Managers\CompanyManager.cs:line 44
at API.Controllers.CompanyController.GetAllCompanies() in E:\src\API\Controllers\CompanyController.cs:line 44
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionFilterAsync>d__28.MoveNext()
Further technical details
EF Core version: (found in project.json or packages.config)
Operating system: Windows 10 Pro
Visual Studio version: Visual Studio 15 Professional
Other details about my project setup:
ASP.NET Core
.NET Core 1.0.1
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
Use AsQueryable() on navigation property
Probably I'm doing something incorrect. Thanks in advance for reading this.
The issue
I need to check the same specific condition (where clause) many times.
I this condition changes I don't want to change all my queries. So I wanted to abstract this condition in a separate method.
Changed it with a extension method (on IQueryable) to:
Everything working fine (generates the same SQL query). Now I also need this where projects is a navigation property:
Imagine that a company has projects. And I only want to retrieve the companies where the user can at least see one project.
After searching a while I learnt about Expression<Func<Project, bool>>
This however resulted in the same exception.
Extra details:
Extension method:
Expression method:
Exception
Further technical details
EF Core version: (found in project.json or packages.config)
Operating system: Windows 10 Pro
Visual Studio version: Visual Studio 15 Professional
Other details about my project setup:
ASP.NET Core
.NET Core 1.0.1
The text was updated successfully, but these errors were encountered: