I recently did a pretty big upgrade from a much older version of Automapper to the latest.
The upgrade caused a lot of headaches, but the Automapper upgrade guide helped a lot ( https://docs.automapper.org/en/stable/8.0-Upgrade-Guide.html ).
One of the last issues I am dealing with is this:
I changed this:
cfg.CreateMap<String, String>()
.ConvertUsing(Conversion.TrimToNull);
To this:
cfg.CreateMap<String, String>()
.ConvertUsing(new Conversion.TrimToNull);
Using a class called Conversion
that looks like this:
public static class Conversion
{
public static String TrimToNull(this String str)
{
return str?.Trim().Coalesce(null);
}
}
But now I am getting this error:
The name 'TrimToNull' does not exist in the type Conversion
I am not sure why it doesn't see TrimToNull
even though it's in the class.
What could I be doing wrong. It worked in the older version of Automapper.
Thanks!
Looking at the auto-mapper guide it seems that they changed the signature from Func<> to Expression<Func<>>. Auto Mapper Convert Using Update
I believe for that reason you want:
cfg.CreateMap<String, String>().ConvertUsing(x => Conversion.TrimToNull(x));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.