dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.67k stars 3.15k forks source link

Global Query is not working in preview6 #16115

Closed jose8789 closed 1 year ago

jose8789 commented 5 years ago

I have a simple repository with a method to retrieve all courses

return Context.Set<Course>().IgnoreQueryFilters()
                        //.Skip(offset).Take(limit)
                        .ToList();

and it gives the current error

Message: 
    System.ArgumentException : Expression of type 'Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalShapedQueryCompilingExpressionVisitor+QueryingEnumerable`1[Oculos.Gnaf.Courses.ReadModels.Models.Course]' cannot be used for parameter of type 'System.Linq.IQueryable`1[Oculos.Gnaf.Courses.ReadModels.Models.Course]' of method 'System.Linq.IQueryable`1[Oculos.Gnaf.Courses.ReadModels.Models.Course] IgnoreQueryFilters[Course](System.Linq.IQueryable`1[Oculos.Gnaf.Courses.ReadModels.Models.Course])'
    Parameter name: arg0
  Stack Trace: 
    at ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
    at Expression.Call(MethodInfo method, Expression arg0)
    at MethodCallExpression1.Rewrite(Expression instance, IReadOnlyList`1 args)
    at ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
    at MethodCallExpression.Accept(ExpressionVisitor visitor)
    at ExpressionVisitor.Visit(Expression node)
    at QueryCompilationContext2.CreateQueryExecutor[TResult](Expression query)
    at Database.CompileQuery2[TResult](Expression query, Boolean async)
    at QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
    at <>c__DisplayClass9_0`1.<Execute>b__0()
    at CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
    at CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
    at QueryCompiler.Execute[TResult](Expression query)
    at EntityQueryProvider.Execute[TResult](Expression expression)
    at EntityQueryable`1.GetEnumerator()
    at List`1.ctor(IEnumerable`1 collection)
    at Enumerable.ToList[TSource](IEnumerable`1 source)

Steps to reproduce

public class Course 
    {
        public string Abbreviation { get; set; }
        public int Id { get; set; }
        public string Name { get; set; }
        public bool IsDeleted { get; set; }
    }

in dbcontex

protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBmodelBuilder.Entity<Course>().HasQueryFilter(x => !x.IsDeleted);
        }

in repository:

return Context.Set().IgnoreQueryFilters()
//.Skip(offset).Take(limit)
.ToList();

Further technical details

EF Core version: 3.0.0-preview6.19304.10 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: IDE: (e.g. Visual Studio 2019 16.2)

ajcvickers commented 5 years ago

@jose8789 First, many thanks for trying preview 6. We really appreciate people trying the previews and filing issues on what they find.

If you haven't seen it already, there is some good information in the preview announcement post about the changes that are happening to LINQ queries for EF Core 3.0. Preview 6 is the first release containing these changes, which means we are both expecting things to be broken, but at the same time very grateful for everyone who tries the release and generated feedback.

Note from triage: In this case, query filters is something that is not working in this preview. @smitpatel Do we have/need a specific issue tracking this?

smitpatel commented 5 years ago

Duplicate of #15264