Reputation: 15770
Can AutoMapper map shared properties?
Entity
public class Entity
{
public static string SomeProperty {get; set;}
...
...
...
}
View Model
public class ViewModel
{
public string SomeProperty {get; set;}
...
...
...
}
Upvotes: 0
Views: 70
Reputation: 1726
You should use a code like this:
Mapper.CreateMap<Entity, ViewModel>()
.ForMember(
dest => dest.SomeProperty,
opt => opt.MapFrom(src => Entity.SomeProperty));
Upvotes: 0
Reputation: 28772
Although I have not used AutoMapper yet, I see no reason why you would not be able to achieve what you are looking for. Based on the project's documentation on Projection, you can write a projector:
Mapper.CreateMap<Entity, ViewModel>()
.ForMember(dest => dest.SomeProperty, opt => opt.MapFrom(src => src.SomeProperty));
// Perform mapping
ViewModel form = Mapper.Map<Entity, ViewModel>(entity);
Upvotes: 1