question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing support for ProjectTo

See original GitHub issue

The following code:

var res = await mContext.Entities
    .ProjectTo<Model>(mMapper.ConfigurationProvider)
    .ToListAsync();

produces an error when executed with mocked db:

at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection`1 parameters, String paramName)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, IEnumerable`1 parameters)
   at EntityFrameworkCoreMock.DbAsyncEnumerable`1.CompileExpression[T](Expression expression)
   at EntityFrameworkCoreMock.DbAsyncEnumerable`1..ctor(Expression expression)
   at EntityFrameworkCoreMock.DbAsyncQueryProvider`1.CreateQuery(Expression expression)
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at AutoMapper.QueryableExtensions.ProjectionExpression.To[TResult](Object parameters, Expression`1[] membersToExpand) in C:\projects\automapper\src\AutoMapper\QueryableExtensions\ProjectionExpression.cs:line 62
   at AutoMapper.QueryableExtensions.Extensions.ProjectTo[TDestination](IQueryable source, IConfigurationProvider configuration, Expression`1[] membersToExpand) in C:\projects\automapper\src\AutoMapper\QueryableExtensions\Extensions.cs:line 76
   at MyCode.IRepository.GetAll()
   at MyTest.RepositoryShould.Add()
Result Message:	
Test method MyTest.RepositoryShould.Add threw exception: 
System.ArgumentException: Expression of type 'System.Linq.IQueryable`1[Model]' cannot be used for return type 'System.Collections.Generic.IEnumerable`1[Entity]'

ProjectTo is AutoMapper extension. Preprequisites: Entity class, Model class, and a map from Entity to Model.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
mc0recommented, Apr 16, 2019

Thanks, will do after Easter.

0reactions
huysentruitwcommented, Apr 16, 2019

If so, please try version 1.0.0.25 or higher, where I’ve downgraded the EF Core dependency.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ProjectTo does not recognize parameterless constructor
NotSupportedException: Only parameterless constructors and initializers are supported in LINQ to Entities. Why? My class does have a ...
Read more >
Casting issue with AutoMapper's ProjectTo method : r/csharp
Hi, I need to use AutoMapper to map db entities (User) to domain entities (UserDto). Instead of Map I just wanted to use...
Read more >
Queryable Extensions
ProjectTo must be the last call in the chain. ORMs work with entities, not DTOs. So apply any filtering and sorting on entities...
Read more >
AutoMapper LINQ Support Deep Dive
My favorite feature of AutoMapper is its LINQ support. If you're using AutoMapper, and not using its queryable extensions, you're missing ...
Read more >
Missing Prefabs when Moving Project to Official Unity ...
Hi! When I transfer my project (2018.2.0b9) to any official version of Unity, my scene is missing almost all of the game objects....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found