【发布时间】:2020-03-06 14:28:55
【问题描述】:
在我的业务层中,我有以下对象
class ParentClass
{
// Parent class properties
ChildClass PrimaryChild { get; set; }
ChildClass SecondaryClass { get; set; }
}
class ChildClass
{
//Child class properties
}
业务规则规定只有一个主要的和一个次要的孩子
在 DAL 中,尽管将其设置为标准的一对多关系是有意义的
class ParentEntity
{
// Parent properties
IEnumerable<ChildEntity> Children { get; set; }
}
class ChildEntity
{
// Child properties
bool IsPrimary { get; set; }
int ParentId { get; set; }
ParentEntity Parent { get; set; }
}
这对数据库很有效,并且在业务规则发生变化的情况下提供了未来的灵活性。
这一切正常,但我发现自己在业务层中手动映射 PrimaryChild 和 SecondaryChild 属性,而其他所有内容都由 automapper 映射。
有没有办法指示 automapper 进行这种映射?我没有运气找到遵循这种结构的示例。
【问题讨论】:
标签: c# .net-core automapper