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

Context.FirstOrDefault throws ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index #14911

Closed
IbrahimShrourou opened this issue Mar 4, 2019 · 6 comments
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Milestone

Comments

@IbrahimShrourou
Copy link

IbrahimShrourou commented Mar 4, 2019

I have a model similar to this one :

    public class Aggregate
    {
        public Aggregate()
        {
        }

        public int Id { get; set; }
        public FirstValueObject FirstValueObject { get; set; }
    }

    public class FirstValueObject
    {
        public FirstValueObject()
        {
        }

        public List<> SecondValueObjects { get; set; }
    }

    public class SecondValueObject
    {
        public SecondValueObject()
        {
        }

        public FourthValueObject FourthValueObject { get; set; }
        public List ThirdValueObjects { get; set; }
    }

    public class ThirdValueObject
    {
        public ThirdValueObject()
        {
        }

        public FourthValueObject FourthValueObject { get; set; }
    }

    public class FourthValueObject
    {
        public FourthValueObject()
        {
        }

        public List FifthValueObjects { get; set; }
    }

    public class FifthValueObject
    {
        public FifthValueObject(int anyValue)
        {
            AnyValue = anyValue;
        }

        public int AnyValue { get; set; }
    }

Then I get the mentioned exception when try to read from the Aggregate entity :
context.Aggregates.FirstOrDefault()
I created a repo you can use to repreduce the issue
here is the error message with the stack trace

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Arg_ParamName_Name'

at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.BindSubqueryProjectionIndex(Int32 projectionIndex, IQuerySource querySource)
at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitOrderByClause(OrderByClause orderByClause, QueryModel queryModel, Int32 index)
at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection1 bodyClauses, QueryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block) at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node) at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block) at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node) at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node) at System.Linq.Expressions.ConditionalExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block) at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node) at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger1 logger, Type contextType)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_01.<Execute>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at OwnsManyIssue.Program.Main(String[] args) in C:\Users\public\Downloads\OwnsManyIssue\OwnsManyIssue\Program.cs:line 50

@smitpatel
Copy link
Member

This works in 3.1
Generated SQL

      SELECT [a].[Id], [t].[Id], [t7].[FirstValueObjectAggregateId], [t7].[Id], [t7].[FirstValueObjectAggregateId0], [t7].[Id0], [t7].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectSecondValueObjectId], [t7].[Id1], [t7].[AnyValue], [t7].[SecondValueObjectFirstValueObjectAggregateId], [t7].[SecondValueObjectId], [t7].[Id2], [t7].[SecondValueObjectFirstValueObjectAggregateId0], [t7].[SecondValueObjectId0], [t7].[Id00], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t7].[FourthValueObjectThirdValueObjectId], [t7].[Id10], [t7].[AnyValue0]
      FROM [Aggregates] AS [a]
      LEFT JOIN (
          SELECT [a0].[Id], [a1].[Id] AS [Id0]
          FROM [Aggregates] AS [a0]
          INNER JOIN [Aggregates] AS [a1] ON [a0].[Id] = [a1].[Id]
      ) AS [t] ON [a].[Id] = [t].[Id]
      LEFT JOIN (
          SELECT [s].[FirstValueObjectAggregateId], [s].[Id], [t0].[FirstValueObjectAggregateId] AS [FirstValueObjectAggregateId0], [t0].[Id] AS [Id0], [s2].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [s2].[FourthValueObjectSecondValueObjectId], [s2].[Id] AS [Id1], [s2].[AnyValue], [t6].[SecondValueObjectFirstValueObjectAggregateId], [t6].[SecondValueObjectId], [t6].[Id] AS [Id2], [t6].[SecondValueObjectFirstValueObjectAggregateId0], [t6].[SecondValueObjectId0], [t6].[Id0] AS [Id00], [t6].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t6].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t6].[FourthValueObjectThirdValueObjectId], [t6].[Id1] AS [Id10], [t6].[AnyValue] AS [AnyValue0]
          FROM [SecondValueObject] AS [s]
          LEFT JOIN (
              SELECT [s0].[FirstValueObjectAggregateId], [s0].[Id], [s1].[FirstValueObjectAggregateId] AS [FirstValueObjectAggregateId0], [s1].[Id] AS [Id0]
              FROM [SecondValueObject] AS [s0]
              INNER JOIN [SecondValueObject] AS [s1] ON ([s0].[FirstValueObjectAggregateId] = [s1].[FirstValueObjectAggregateId]) AND ([s0].[Id] = [s1].[Id])
          ) AS [t0] ON ([s].[FirstValueObjectAggregateId] = [t0].[FirstValueObjectAggregateId]) AND ([s].[Id] = [t0].[Id])
          LEFT JOIN [SecondValueObject_FifthValueObjects] AS [s2] ON ([t0].[FirstValueObjectAggregateId] = [s2].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId]) AND ([t0].[Id] = [s2].[FourthValueObjectSecondValueObjectId])
          LEFT JOIN (
              SELECT [t1].[SecondValueObjectFirstValueObjectAggregateId], [t1].[SecondValueObjectId], [t1].[Id], [t4].[SecondValueObjectFirstValueObjectAggregateId] AS [SecondValueObjectFirstValueObjectAggregateId0], [t4].[SecondValueObjectId] AS [SecondValueObjectId0], [t4].[Id] AS [Id0], [t5].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t5].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t5].[FourthValueObjectThirdValueObjectId], [t5].[Id] AS [Id1], [t5].[AnyValue]
              FROM [ThirdValueObject] AS [t1]
              LEFT JOIN (
                  SELECT [t2].[SecondValueObjectFirstValueObjectAggregateId], [t2].[SecondValueObjectId], [t2].[Id], [t3].[SecondValueObjectFirstValueObjectAggregateId] AS [SecondValueObjectFirstValueObjectAggregateId0], [t3].[SecondValueObjectId] AS [SecondValueObjectId0], [t3].[Id] AS [Id0]
                  FROM [ThirdValueObject] AS [t2]
                  INNER JOIN [ThirdValueObject] AS [t3] ON (([t2].[SecondValueObjectFirstValueObjectAggregateId] = [t3].[SecondValueObjectFirstValueObjectAggregateId]) AND ([t2].[SecondValueObjectId] = [t3].[SecondValueObjectId])) AND ([t2].[Id] = [t3].[Id])
              ) AS [t4] ON (([t1].[SecondValueObjectFirstValueObjectAggregateId] = [t4].[SecondValueObjectFirstValueObjectAggregateId]) AND ([t1].[SecondValueObjectId] = [t4].[SecondValueObjectId])) AND ([t1].[Id] = [t4].[Id])
              LEFT JOIN [ThirdValueObject_FifthValueObjects] AS [t5] ON (([t4].[SecondValueObjectFirstValueObjectAggregateId] = [t5].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId]) AND ([t4].[SecondValueObjectId] = [t5].[FourthValueObjectThirdValueObjectSecondValueObjectId])) AND ([t4].[Id] = [t5].[FourthValueObjectThirdValueObjectId])
          ) AS [t6] ON ([s].[FirstValueObjectAggregateId] = [t6].[SecondValueObjectFirstValueObjectAggregateId]) AND ([s].[Id] = [t6].[SecondValueObjectId])
      ) AS [t7] ON [t].[Id] = [t7].[FirstValueObjectAggregateId]
      ORDER BY [a].[Id], [t7].[FirstValueObjectAggregateId], [t7].[Id], [t7].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectSecondValueObjectId], [t7].[Id1], [t7].[SecondValueObjectFirstValueObjectAggregateId], [t7].[SecondValueObjectId], [t7].[Id2], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t7].[FourthValueObjectThirdValueObjectId], [t7].[Id10]

@TheAifam5
Copy link

TheAifam5 commented Jan 13, 2020

We encounter similar issue while using OData.

We updated from dotnet 2.2 to 3.1 today. Our model looks like this:

public class CommentEntity {
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  [Key]
  public virtual Guid Id { get; set; }

  [...]
}

public class OrderEntity {
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  [Key]
  public virtual Guid Id { get; set; }

  [...]
}

public class CustomerEntity {
  [... id, collections, etc..]
  public virtual ICollection<CommentEntity> Comments { get; set; }
  public virtual ICollection<OrderEntity> Orders { get; set; }

  public CustomerEntity() {
    Comments = new HashSet<CommentEntity>();
    Orders = new HashSet<OrderEntity>();
  }
}

We determined that the issue is while accessing two or more collections at the same time.

If we want to access two lists at the same time, we get following exception:

  {
  "error": {
    "code": "",
    "message": "The query parameter 'Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')' is not supported.",
    "details": [],
    "innererror": {
      "message": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')",
      "type": "System.ArgumentOutOfRangeException",
      "stacktrace": "   at System.Collections.Generic.List`1.get_Item(Int32 index)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitExtension(Expression extensionExpression)\n   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)\n   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)\n   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)\n   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)\n   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)\n   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)\n   at Microsoft.EntityFrameworkCore.Query.RelationalCollectionShaperExpression.VisitChildren(ExpressionVisitor visitor)\n   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitExtension(Expression extensionExpression)\n   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)\n   at Microsoft.EntityFrameworkCore.Query.CollectionPopulatingExpression.VisitChildren(ExpressionVisitor visitor)\n   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.VisitExtension(Expression extensionExpression)\n   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)\n   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)\n   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)\n   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)\n   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.Visit(Expression node, IReadOnlyList`1& projectionColumns)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression)\n   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)\n   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)\n   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)\n   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()\n   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)\n   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)\n   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)\n   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.IEnumerable.GetEnumerator()\n   at Microsoft.AspNet.OData.EnableQueryAttribute.SingleOrDefault(IQueryable queryable, IWebApiActionDescriptor actionDescriptor)\n   at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\n   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)"
    }
  }
}

We also found, that if we try to fetch 3 or more lists at the same time, we get another exception:

{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. No coercion operator is defined between types 'System.String' and 'System.Boolean'.",
    "details": [],
    "innererror": {
      "message": "No coercion operator is defined between types 'System.String' and 'System.Boolean'.",
      "type": "System.InvalidOperationException",
      "stacktrace": "   at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.CreateGetValueExpression(ParameterExpression dbDataReader, Int32 index, Boolean nullable, RelationalTypeMapping typeMapping, Type clrType)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)\n   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)\n   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)\n   at Microsoft.EntityFrameworkCore.Query.RelationalCollectionShaperExpression.VisitChildren(ExpressionVisitor visitor)\n   at Microsoft.EntityFrameworkCore.Query.CollectionPopulatingExpression.VisitChildren(ExpressionVisitor visitor)\n   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)\n   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)\n   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.Visit(Expression node, IReadOnlyList`1& projectionColumns)\n   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression)\n   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)\n   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)\n   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()\n   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)\n   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)\n   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)\n   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.IEnumerable.GetEnumerator()\n   at Microsoft.AspNet.OData.EnableQueryAttribute.SingleOrDefault(IQueryable queryable, IWebApiActionDescriptor actionDescriptor)\n   at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\n   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)"
    }
  }
}

We are not sure if that's an issue with OData, or with LINQ or with EFCore.

Best regards,
TheAifam5

@smitpatel
Copy link
Member

@TheAifam5 - Please file a new issue with full repro code. This issue has been fixed 3.1 and pending committing a regression test to code base.

@TheAifam5
Copy link

@smitpatel I am aware of that PR. Last time I checked was in review state.

@smitpatel
Copy link
Member

@TheAifam5 - There is no PR associated. I am referring to comment I have posted here #14911 (comment)

@smitpatel smitpatel self-assigned this Aug 28, 2020
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed add-regression-test labels Aug 28, 2020
@smitpatel smitpatel modified the milestones: Backlog, 3.1.0 Aug 28, 2020
@smitpatel
Copy link
Member

Fixed in #22282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Projects
None yet
Development

No branches or pull requests

5 participants