automapper, Can I auto assign Guid to UserId of my UserDTO?
I want to assign Guid to UserId of my UserDTO if UserId is Null. Is it possible to do this in the CreateMap or creating any formatter?. I am using automapper as an attribute on my Actions in controller.
protected override void Configure()
{
Mapper.CreateMap<User, UserDT开发者_开发问答O>()
.ForMember(d => d.FullName, o => o.MapFrom(s => s.FirstName + " " + s.LastName));
}
Why not just:
public class UserDTO
{
string _userId;
public string UserId
{
get
{
if (_userId == null)
_userId = new Guid().ToString();
return _userId;
}
set { _userId = value; }
}
}
精彩评论