Well I am trying to map my user profile model to/from user profile viewmodel, but it will not work since they do not share all the data fields:
Model:
public class UserProfile
{
public virtual string Id { get; set; }
public virtual string Interests { get; set; }
public virtual string Biography { get; set; }
public virtual string SmokingAttitude { get; set; }
public virtual string DrinkingAttitude { get; set; }
public virtual string Projects { get; set; }
public virtual string Groups { get; set; }
}
ViewModel:
public class UserProfileViewModel
{
[Display(Name = "Interests")]
public string Interests { get; set; }
[Display(Name = "Biography/Comments")]
public string Biography { get; set; }
[Display(Name = "Attitude to Smoking")]
public string SmokingAttitude { get; set; }
[Display(Name = "Attitude to Drinking")]
public string DrinkingAttitude { get; set; }
[Display(Name = "Projects working on")]
public string Projects { get; set; }
[Display(Name = "Groups joined")]
public string Groups { get; set; }
public IEnumerable<SelectListItem> AttitudeList
{
get
{
return new[]{
new SelectListItem {Value = "not specified", Text = "not specified"},
new SelectListItem {Value = "very negative", Text = "very negative"},
new SelectListItem {Value = "negative", Text = "negative"},
new SelectListItem {Value = "compromisable", Text = "compromisable"},
new SelectListItem {Value = "neutral", Text = "neutral"},
new SelectListItem {Value = "positive", Text = "positive"},
};
}
}
}
As you can see, the ID attribute is stored in user profile model(as a key to user table), but not on user profile viewmodel. The user profile viewmodel though, has an additional field AttitudeList defined for selection/dropdown list manipulation. I think this is the cause of automapper not working, but I am totally clueless how to get by this.
Can anyone please help? The idea is simply to map common fields from model to/from viewmodel, while leaving out distinct fields. I hope I dont have to just manually map them writing tens of lines of code...