Automapper ProjectTo does not allow mapping properties to custom methods

automapper automapper-6 entity-framework-6 linq

Popular Answer

This is what Entity Framework prohibits, not AutoMapper. Simply by using your mapping setup, AutoMapper creates aSelect to the underlying query provider using LINQ expression.

Since Entity Framework is the underlying query provider in your scenario, it should come as no surprise that Entity Framework is unable to transform any given method into SQL. Only a few methods, including Count, Sum, and a few string/DateTime/primitive ones, are understood by EF.

So the exception message is quite accurate - EF doesn't understand this method you've given it, and therefore has no way to translate that method to SQL.

However, if you look at the Package AutoMapper.EF6, there may be hope. It contains theDelegateDecompiler package that analyses your method's behaviour using IL inspection, decompiles it, and then passes the result as an expression to the query provider.

If it seems difficult, it probably is, so before continuing, you should really have a firm grasp of how LINQ works.

0
8/24/2018 5:54:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow