Automapper ResolveUsing cause “Can't resolve this to Queryable Expression”

陌路散爱 提交于 2019-12-04 23:50:16

As the documentation states, you can't use custom resolvers in queryable expressions:

https://github.com/AutoMapper/AutoMapper/wiki/Queryable-Extensions#supported-mapping-options

You can, however, use MapFrom:

Mapper.CreateMap<Entity, EntityModel>()
    .ForMember(dest => dest.Password, op => op.MapFrom(src => "TEST"));

I'm guessing that's not actually what you want to do for that Password property but that's how you can fix the example.

I think what your issue is that you're trying to call .NET code in the query to the database which is erroring.

What you can do is wherever you use the projection instead of using .ProjectTo use .UseAsDataSource(Configuration).AfterProjection and .BeforeProjection. Both of these will allow you to get it to project the values into the right fields and then operate on the results to encrypt/decrypt so you get the actual values you're looking for.

Once you pass those 2, then you call .For();

Otherwise you're always operating on the actual SQL Query which can't execute .NET code obviously.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!