AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Implement count in expansion options #197

Open lenardchristopher opened 8 months ago

lenardchristopher commented 8 months ago

Addresses #137

Note: First time touching the code of this repo. I don't see any contribution docs, so I'm not sure what is necessary.

The test I wrote fails with the following exception

Expression of type 'System.Int32' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[AutoMapper.OData.EFCore.Tests.Model.ProductModel]' of method 'System.Collections.Generic.List`1[AutoMapper.OData.EFCore.Tests.Model.ProductModel] ToList[ProductModel](System.Collections.Generic.IEnumerable`1[AutoMapper.OData.EFCore.Tests.Model.ProductModel])' (Parameter 'arg0')
   at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
   at AutoMapper.AspNet.OData.Visitors.MethodAppender.VisitMethodCall(MethodCallExpression node) in /Users/chrislenard/repos/AutoMapper.Extensions.OData/AutoMapper.AspNetCore.OData.EFCore/Visitors/MethodAppender.cs:line 43
   at AutoMapper.AspNet.OData.Visitors.MethodAppender.AppendQueryMethod(Expression expression, ODataExpansionOptions expansion, ODataQueryContext context) in /Users/chrislenard/repos/AutoMapper.Extensions.OData/AutoMapper.AspNetCore.OData.EFCore/Visitors/MethodAppender.cs:line 23

I interpret this to mean that COUNT was used properly, but handling the value in the result is throwing an error. Would love some advice. Thanks.

lenardchristopher commented 8 months ago

@dotnet-policy-service agree

BlaiseD commented 8 months ago

It's probably better to place the test here. The test should confirm that the count filed exists in the result. It should fail if run against the current code.