我使用的是EF4.1 DbContext代码生成,它创建了如下POCO实体:
public partial class Employee
{
public Employee()
{
this.Roles = new HashSet<Role>();
}
public System.Guid EmployeeGUID { get; set; }
public string EmployeeID { get; set; }
public string PIN { get; set; }
public string FullName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string JobTitle { get; set; }
public string DepartmentDescription { get; set; }
public Nullable<System.DateTime> LatestHireDate { get; set; }
public string CompanyEmailAddress { get; set; }
public Nullable<System.Guid> SupervisorGUID { get; set; }
public string SupervisorFullName { get; set; }
public string SupervisorCompanyEmailAddress { get; set; }
public string JobCode { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
这是如何实现的?
我将创建DTO(数据传输对象)来表示真正需要序列化的内容,而不是序列化DBContext实体。然后,我会使用类似AutoMapper的东西来将DBContext实体映射到DTO。
更新:这有点过时了,但作者解释了AutoMapper的一些伟大用途。