sasi prabhu

sasi prabhu

  • NA
  • 49
  • 686

Auttomapper source to destination with List<t>

Mar 4 2022 4:13 PM

 .ForPath(des => des.Variables.Sugar, src => src.MapFrom(m => m.Order.)

This Order type is List  in the list i have "itemname" property. i want to map this property to "des.Variables.Sugar"

please tell me how can map this 

below is my model details

Source Model

public  class OOTFXFnBOrderModel
{
    public string SpaceName { get; set; }
    public string SpaceEmailAddress { get; set; }
    public List Order { get; set; }
}

public class Order
{
    public string ItemId { get; set; }
    public string ItemName { get; set; }
    public string ItemType { get; set; }
    public string ItemCategory { get; set; }
    public bool IsVeg { get; set; }
    public string Calories { get; set; }
    public string ImageUrl { get; set; }
    public string Comments { get; set; }
    public bool IsDecaf { get; set; }
    public int Quantity { get; set; }
    public string AllergyInformation { get; set; }
    public List Customizations { get; set; }
    //public VariableType VariableType { get; set; }
}

Destination Model

public class FnBServiceNowAddToCartModel
{
    public Int32 Sysparm_quantity { get; set; }
    public Variables Variables { get; set; }
}

public  class Variables
{
    public string Brown_sugar { get; set; }
    public string Customizations { get; set; }
    public string Coffee_type { get; set; }
    public bool Milk { get; set; }
    public string Dates { get; set; }
    public string Sweetener { get; set; }
    public string Cookies { get; set; }
    public string Mint { get; set; }
    public string Honey { get; set; }
    public string Coffee { get; set; }
    public string Coffee_mate { get; set; }
    public string Sugar { get; set; }
    public string Requested_by { get; set; }
    public string Location { get; set; }
}

Answers (2)