How to specify mapping rule when names of properties differ

后端 未结 4 1802
孤独总比滥情好
孤独总比滥情好 2020-11-29 19:53

I am a newbie to the Automapper framework. I have a domain class and a DTO class as follows:

public class Employee
{
   public long Id {get;set;}
   public s         


        
4条回答
  •  萌比男神i
    2020-11-29 19:56

    We can also specify on Class attributes for mapping

    From https://docs.automapper.org/en/stable/Conventions.html#attribute-support

    Attribute Support

    AddMemberConfiguration().AddName(); * Currently is always on

    Looks for instances of SourceToDestinationMapperAttribute for Properties/Fields and calls user defined isMatch function to find member matches.

    MapToAttribute is one of them which will match the property based on name provided.

    public class Foo
    {
        [MapTo("SourceOfBar")]
        public int Bar { get; set; }
    }
    

提交回复
热议问题