Search code examples
c#automapperautomapper-11

Automapper only creates new object without map


I have two objects which I can't map.

enter image description here

Here are my objects definitions:

public class DcMarkupValue
{
    public DateTime StartDate { get; }
    public DateTime EndDate { get; }
    public decimal MarkupPrice { get; }
    public decimal MarkupChange { get; }
}

public class MarkupByUOMandCategoryIdEntity
{
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public decimal MarkupPrice { get; set; }
    public decimal MarkupChange { get; set; }
    public decimal MarkupPercentChange { get; set; }
    public string UomCode { get; set; }
}

In this example, you can see that Automapper does not perform the mapping. StartDate field not mapped. What have I missed?


Solution

  • Add setter to each property in DcMarkupValue.

    public class DcMarkupValue
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public decimal MarkupPrice { get; set; }
        public decimal MarkupChange { get; set; }
    }