我正在尝试开发一个使用带有层次结构的json并将其转换为我的DTO类的应用程序。基本概念是,我有两个从C继承的类(N和R),并且N可能与其他类型为C的对象有联系。
根
| ----> A(NModel)
| --------- | -----> B(NModel)
| --------- | -----> C(RModel)
我有以下DTO类:
public class ComponentModel
{
public Guid Id { get; set; }
}
public class RModel : ComponentModel
{
}
public class NModel : ComponentModel
{
public List<ComponentModel> components { get; set; }
}
public class ComponentModel
{
public Guid Id { get; set; }
}
public class RModel : ComponentModel
{
}
public class NModel : ComponentModel
{
public List<ComponentModel> components { get; set; }
}
这个实体:
public class CEntity : IEntity
{
public Guid Id { get; set; }
}
public class REntity : CEntity
{
}
public class NEntity : CEntity
{
public virtual List<NRIntermediate> NRIntermediates { get; set; }
}
public class NRIntermediate : IEntity
{
public Guid Id { get; set; }
public Guid NID { get; set; }
public NEntity NInstance { get; set; }
public Guid ComponentID { get; set; }
public CEntity Component { get; set; }
}
public class CEntity : IEntity
{
public Guid Id { get; set; }
}
public class REntity : CEntity
{
}
public class NEntity : CEntity
{
public virtual List<NRIntermediate> NRIntermediates { get; set; }
}
public class NRIntermediate : IEntity
{
public Guid Id { get; set; }
public Guid NID { get; set; }
public NEntity NInstance { get; set; }
public Guid ComponentID { get; set; }
public CEntity Component { get; set; }
}
cfg.CreateMap<CEntity, ComponentModel>().ReverseMap();
cfg.CreateMap<REntity, RModel>().ReverseMap();
cfg.CreateMap<CEntity, ComponentModel>().ReverseMap();
cfg.CreateMap<REntity, RModel>().ReverseMap();
在这种情况下,我仅获得Root对象映射以及与您的孩子的关系,但嵌套的对象未得到处理
感谢您的时间!
编辑:更好的样式