【发布时间】:2013-08-26 14:09:46
【问题描述】:
我有如下的数据库模型。这里我描述了我在 EF 模型中的实体:
public class Person
{
public int Id { get; set; }
public int AddressId { get; set; }
public int RoleId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
public class Address
{
public int Id { get; set; }
public int CountryId { get;set; }
public string City { get; set; }
}
public class Role
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Country
{
public int Id { get; set; }
public string Name { get; set; }
}
在前端我有允许编辑用户信息的管理界面。 因此,在每条网格线中,我都显示了以下 DTO 对象:
public class SystemUser
{
public string UserName { get; set; }
public string Email { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Role { get; set; }
}
我的主要问题 - 在执行编辑后将其映射回实体的最佳方法是什么,我使用 AutoMapper 或其他东西取回 DTO?
或者我在这里做了什么完全愚蠢的事情?
编辑: 我还有另一个挑战:我想尽量减少到数据库的往返次数。
【问题讨论】:
标签: entity-framework domain-driven-design automapper dto