public class Restaurant
{
public int RestaurantId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public bool Active { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
public decimal? Lat { get; set; }
public decimal? Long { get; set; }
}
public class RestaurantInfo
{
public int RestaurantId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public bool Active { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
public decimal? Lat { get; set; }
public decimal? Long { get; set; }
}
Auto Mapper
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Restaurant, RestaurantInfo>();
CreateMap<Restaurant, Address>();
}
}
public RestaurantInfo GetRestaurantById(IMapper mapper)
{
var restaurant = new Restaurant
{
RestaurantId = 1,
Name = "Blueline",
Slug = "Blueline",
Active = true,
Address1 = "XYZ",
Address2 = "PQR"
};
return mapper.Map<Restaurant>(restaurantInfo);
}
My source class is Restaurant and Destination class is RestaurantInfo. Auto mapper is converting Restaurant back into RestaurantInfo, but issue is Address property of RestaurantInfo is not getting initialized with all address related properties of Restaurant. I think my mapping code is not correct. Suggest me correct mapping for above issue.