11.0 Upgrade Guide¶
AutoMapper now targets .Net Standard 2.1 and doesn’t work on .Net Framework¶
ForAllMaps
, ForAllPropertyMaps
, Advanced
and other “missing” APIs¶
Some APIs were hidden for normal usage. To light them up, you need to add an using
for AutoMapper.Internal
and call the Internal
extension method on the configuration object.
Most users don’t need these advanced methods. Some expose internals and are not subject to the usual semantic versioning rules. To avoid such tight coupling to AutoMapper, you should try to stick to the public API.
Mapping into existing collections¶
When calling Map
with an existing readonly collection, such as IEnumerable<>
, the setter will be used to replace it. If you actually have to map into that collection, you need to change its type to a writable
collection, such as List<>
, HashSet<>
, ICollection<>
, IList<>
or IList
. Alternatively, you can remove the setter or set UseDestinationValue
.
CreateProjection
¶
If you don’t use Map
, just ProjectTo
, you should use CreateProjection
instead of CreateMap
. That way you’ll use only the API subset supported by ProjectTo
and start-up should be faster.
System.ComponentModel.TypeConverter
is no longer supported¶
It was removed for performance reasons. So it’s best not to use it anymore. But if you must, there is a sample in the test project.
Generating interface proxies is disabled by default¶
That was misleading for a lot of people. You can opt-in per map with AsProxy
(and ForAllMaps
if needed).
MapToAttribute
and IgnoreMapAttribute
were removed¶
These were older attributes, unrelated to the newer attributes API. You can switch to the fluent API or implement the attributes in your own code. Check the tests for sample code (here and here).
Global pre and postfixes are now applied in all maps¶
They used to be applied only in the global configuration, now they are applied in all profiles, consistent with how settings work.
ForAllOtherMembers
was removed¶
That was used to disable mapping by convention, not something we want to support. When only used for validation, it can be replaced with MemberList.None
.
C# Indexers (Item
property)¶
These used to be ignored by default, but that’s expensive and most types don’t have them. So you have to explicitly ignore them. Globally, with ShouldMapProperty
or GlobalIgnores
, or per member.
Configuration performance¶
While you should get improvements without code changes, you can do even better. Definitely use CreateProjection
with ProjectTo
. If you’re an advanced user and you’re confident in your test coverage, you can disable any features you don’t need. Needless to say, do measure to see if these help in your particular case.