Automapper继承的类Issue

时间:2018-09-04 18:45:19

标签: automapper automapping

域对象类:

public class DomainObjects
{
    public string Firstame { get; set; }
    public string LastName { get; set; }
}

public class Address
{
    public string AddressName { get; set; }
}

数据对象类:

public class DataObjects : SharedObjects.DomainObjects
{
    private string fullName;
    public string FullName { get { return fullName; } set { fullName = Firstame + LastName; } }    

    public List<Address> address { get; set; }

}

public class Address
{
    public string AddressName { get; set; }
}

主程序:

SharedObjects.DomainObjects temp = new SharedObjects.DomainObjects()
        {
            Firstame = "ABC",
            LastName = "D"
        };

        List<SharedObjects.Address> addresses = new List<SharedObjects.Address>()
        {
            new SharedObjects.Address()
            {
             AddressName = "Address1"
            },
             new SharedObjects.Address()
            {
             AddressName = "Address2"
            }
        };

        Mapper.Initialize(cfg => cfg.CreateMap<List<SharedObjects.Address>, List<Data.Address>>());

        var data = Mapper.Map<List<SharedObjects.Address>, List<Data.Address>>(addresses);

我需要将地址的域对象作为集合自动映射到数据对象的地址。

单个地址记录能够自动映射,涉及到集合时,数据分配为空。

请告诉我如何使用自动映射器来实现。

0 个答案:

没有答案