How to use AutoMapper .ForMember?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
ForMember is the AutoMapper hook you use when convention-based mapping is not enough for a specific destination property. It lets you say exactly how one destination member should be populated, ignored, transformed, or conditionally mapped.
What ForMember Configures
AutoMapper starts with conventions: properties with matching names and compatible types are copied automatically. ForMember is for the exceptions.
You use it on a map definition like this:
The first lambda points to the destination member. The second lambda configures how AutoMapper should fill it.
Common ForMember Operations
The most useful patterns are:
- '
MapFromfor custom source expressions' - '
Ignorewhen a destination property should not be mapped' - '
ConditionorPreConditionfor selective mapping' - '
NullSubstitutefor null fallback values' - '
ConvertUsingwhen a member needs a value converter'
Here is a practical example:
This is the most common use of ForMember: a destination type that does not match the source one-to-one.
MapFrom, Ignore, and Conditions
MapFrom is the core operation. It answers, "Where should this destination member get its value?"
Ignoring is equally important when a destination field is computed elsewhere:
Conditional mapping is useful when source data is incomplete or expensive to compute:
PreCondition runs before AutoMapper resolves the source value. Condition runs later. That distinction matters when the mapping expression is expensive or fragile.
ForMember and Nested Data
You can flatten nested source structures with MapFrom:
If you need to configure a nested destination path instead of a top-level destination member, use ForPath, not ForMember.
That is a common source of confusion:
- '
ForMember: top-level destination property' - '
ForPath: nested destination path'
Keep Mapping Rules Small
AutoMapper profiles are best when they describe mapping, not business workflows. If a mapping needs database access, service calls, or complex branching, that logic usually belongs outside the profile.
A good rule is:
- shape changes and simple formatting belong in
ForMember - business decisions belong in application code
That separation keeps the mapping configuration readable and testable.
ProjectTo Versus In-Memory Mapping
Be careful if you use ProjectTo with LINQ providers such as Entity Framework. Not every ForMember configuration can be translated to SQL.
Simple MapFrom expressions often work well. Arbitrary .NET method calls, custom resolvers, or some converters may not translate. If the map is for database projection, keep the expression translation-friendly.
Common Pitfalls
The biggest mistake is writing the lambda against the source member instead of the destination member. In ForMember, the first lambda must point to the destination property.
Another common mistake is using ForMember for nested destination paths. That is a ForPath scenario.
People also put too much business logic into mapping profiles. If a profile starts looking like a service layer, the design is drifting.
Finally, remember that some member-level conversions work only for in-memory mapping and not for query translation with ProjectTo.
Summary
- Use
ForMemberwhen AutoMapper conventions are not enough for one destination property. - '
MapFrom,Ignore,NullSubstitute, and conditions are the most common options.' - The configured lambda targets a destination member, not a source member.
- Use
ForPathwhen the destination member is nested. - Keep mapping profiles focused on shape conversion, not full business logic.

