AutoMapper 一对多关系
我开始在我的项目中使用 AutoMapper。
为此,我想要执行以下“一对多”映射:
来源:
public class Team
{
int Id { get; set; }
string TeamName { get; set; }
List<Person> Member { get; set; }
}
public class Person
{
int Id { get; set; }
string Name { get; set; }
}
目的地:
public class TeamDetailsViewModel
{
int Id { get; set; }
string TeamName { get; set; }
List<int> MemberIds { get; set; }
}
如何继续使用 AutoMapper?这可能吗?
预先非常感谢。
I'm starting to use AutoMapper for my project.
For this I want to do the following 'one-to-many' mapping:
Source:
public class Team
{
int Id { get; set; }
string TeamName { get; set; }
List<Person> Member { get; set; }
}
public class Person
{
int Id { get; set; }
string Name { get; set; }
}
Destination:
public class TeamDetailsViewModel
{
int Id { get; set; }
string TeamName { get; set; }
List<int> MemberIds { get; set; }
}
How to proceed with AutoMapper? Is this possible?
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这张地图应该适合您:
仅供参考...如果您从数据库获取团队,请确保您渴望加载成员列表。
This map should work for you:
FYI...If you are getting the Team from a db, make sure you are eager loading the Member list.