开发者

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; }

    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜