C# 自动映射嵌套集合映射
我有一个有点复杂的类结构,我想用自动映射器映射。我尝试了几件事,但都没有成功 我有几个模型类,如下所示C# 自动映射嵌套集合映射,c#,.net,automapper,C#,.net,Automapper,我有一个有点复杂的类结构,我想用自动映射器映射。我尝试了几件事,但都没有成功 我有几个模型类,如下所示 public class PersonModel { public string FirstName { get; set; } public string MiddleName { get; set; } public string LastName { get; set; } public ICollec
public class PersonModel
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public ICollection<AddressModel> Address { get; set; }
}
public class AddressModel
{
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Line3 { get; set; }
public string City { get; set; }
public StateModel State { get; set; }
public string PostCode { get; set; }
}
公共类PersonModel
{
公共字符串名{get;set;}
公共字符串MiddleName{get;set;}
公共字符串LastName{get;set;}
公共ICollection地址{get;set;}
}
公共类寻址模型
{
公共字符串Line1{get;set;}
公共字符串第2行{get;set;}
公共字符串第3行{get;set;}
公共字符串City{get;set;}
公共状态模型状态{get;set;}
公共字符串邮政编码{get;set;}
}
现在我有一些其他的课程,如下所示
public partial class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public virtual ICollection<PersonAddress> PersonAddress { get; set; }
}
public partial class PersonAddress
{
public int Id { get; set; }
public int? PersonId { get; set; }
public int? AddressId { get; set; }
public virtual Address Address { get; set; }
public virtual Person Person { get; set; }
}
public partial class Address
{
public int Id { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Line3 { get; set; }
public string City { get; set; }
public string PostCode { get; set; }
}
公共部分类人员
{
公共int Id{get;set;}
公共字符串名{get;set;}
公共字符串MiddleName{get;set;}
公共字符串LastName{get;set;}
公共虚拟ICollection PersonalAddress{get;set;}
}
公共部分类角色地址
{
公共int Id{get;set;}
公共int?PersonId{get;set;}
public int?AddressId{get;set;}
公共虚拟地址{get;set;}
公共虚拟人{get;set;}
}
公共部分类地址
{
公共int Id{get;set;}
公共字符串Line1{get;set;}
公共字符串第2行{get;set;}
公共字符串第3行{get;set;}
公共字符串City{get;set;}
公共字符串邮政编码{get;set;}
}
它们是一些更嵌套的属性,为了简单和使问题更精确,我删除了这些属性。我想将PersonModel与其嵌套属性一起映射,并进行反向映射。我正在使用EF core和.NET core web API
请帮忙