I am receiving PostDTO object in the controller and I am mapping it to Post entity and updating database. The problem occurs because PostDTO doesn't have Status property and Post entity does have Status property, so when I map PostDTO to Post, Post.Status becomes null. I don't want it to be null, I want it to stay unaffected in database. I could retrieve post from database and manually map Status property but is there better solution for this?
public class PostDTO
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public bool Urgent { get; set; }
}
public class Post
{
public long Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public bool Urgent { get; set; }
public string Status { get; set; }
}
var post = _mapper.Map<Post>(postDto); //here post.Status becomes null
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…