想请教大家一个EF的问题,EF里面的Entity,通过Autimapper转换DTO,但是怎么转换Entity里面的导航属性呢?
比如:
Public Class User
{
Public int ID{get;set;}
Public string UserName{get;set;}
Public string Role{get;set;}
}
Public Class Role
{
Public int ID{get;set;}
Public string RoleName{get;set;}
Public virtual List<User> Users{ get; set;}
}
Public Class UserDto
{
Public int ID{get;set;}
Public string UserName{get;set;}
Public int RoleID{get;set;}
Public string RoleName{get;set;}
}
该怎么实现User实体转换成UserDto呢?主要是导航属性的转换不怎么明白的。
Autimapper 应该是 AutoMapper 吧
类似这样
Mapper.CreateMap<Project, ProjectDTO>().ForMember(dest => dest.Contact, opt => opt.MapFrom(src => src.EmailConfig.Contact));