嵌套的Enumerable属性

时间:2015-12-03 19:45:14

标签: automapper

我想使用automapper将嵌套的可枚举属性映射到现有的可枚举嵌套属性中。

以下是问题简化,我有Entities对象,它们实现了IEntity Interface和Models对象,它们实现了IModel接口。

我想使用IModel对象轻松快捷地更新IEntity对象

示例:

public class PersonEntity : IEntity 
{ 
    public int Id { get; set; } 
    public string Name { get; set }
    public IEnumerable<AddressEntity> Addresses { get; set }
}

public class AddressEntity : IEntity 
{ 
    public int Id { get; set; } 
    public string Street { get; set }
    public string entityField { get; set }
}

public class PersonModel : IModel 
{ 
    public int Id { get; set; } 
    public string Name { get; set }
    public IEnumerable<AddressModel> Addresses { get; set }
}

public class AddressModel : IModel 
{ 
    public int Id { get; set; } 
    public string Street { get; set }
}

如果我有这两个实例og PersonEntity和AddressEntity:

var personModel = new PersonModel() 
    {
        Id = 1,
        Name = "Name",
        Addresses = new List<AddressModel>() {
            new AdressModel() { Id =  1, Street = "Street B" }
        }


var person = new PersonEntity() 
    {
        Id = 1,
        Name = "Name",
        Addresses = new List<AddressEntity>() {
            new AdressEntity() { Id =  1, Street = "StreetA", EntityField  ="entityValue" }
        }

如何通过ID(地址元素)映射,仅按StreetB值删除StreetA值,并保持现有的entityField值不变?

谢谢你的帮助!

0 个答案:

没有答案