TheBoubou
TheBoubou

Reputation: 19903

Automapper : copy some properties

I have a 2 instances my class "Person"

public class Person
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public List<Address> PropertyName { get; set; }      
}

var pers1 = new Person();
var pers2 = new Person();

Is it possible to copy a specific properties of "pers2" to "pers1" ? Is it possible to copy all properties except one from "pers2" to "pers1" ?

Thanks,

Upvotes: 0

Views: 672

Answers (1)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21366

You can ignore properties as you want

  Mapper.CreateMap<Person, Person>() 
          .ForMember(person=> person.LastName , opt => opt.Ignore())

Upvotes: 3

Related Questions