AutoMapper は共有プロパティをマップできますか?
実在物
public class Entity
{
public static string SomeProperty {get; set;}
...
...
...
}
モデルを見る
public class ViewModel
{
public string SomeProperty {get; set;}
...
...
...
}
AutoMapper は共有プロパティをマップできますか?
実在物
public class Entity
{
public static string SomeProperty {get; set;}
...
...
...
}
モデルを見る
public class ViewModel
{
public string SomeProperty {get; set;}
...
...
...
}
私はまだAutoMapperを使用していませんが、あなたが探しているものを達成できない理由はわかりません。Projectionに関するプロジェクトのドキュメントに基づいて、次のようなプロジェクターを作成できます。
Mapper.CreateMap<Entity, ViewModel>()
.ForMember(dest => dest.SomeProperty, opt => opt.MapFrom(src => src.SomeProperty));
// Perform mapping
ViewModel form = Mapper.Map<Entity, ViewModel>(entity);
次のようなコードを使用する必要があります。
Mapper.CreateMap<Entity, ViewModel>()
.ForMember(
dest => dest.SomeProperty,
opt => opt.MapFrom(src => Entity.SomeProperty));