sどうすれば次のようなことができますか?
.ForMember(dest => dest.Ad, opt => opt.MapFrom(src => src.Ask_Id == null ? null : new Ask { Id = src.Ask_Id }))
サポートされていないマッピングエラーが発生します。
ありがとう。
sどうすれば次のようなことができますか?
.ForMember(dest => dest.Ad, opt => opt.MapFrom(src => src.Ask_Id == null ? null : new Ask { Id = src.Ask_Id }))
サポートされていないマッピングエラーが発生します。
ありがとう。
クラスオブジェクトがどのように見えるかわかりません。以下のようなクラスがあると仮定すると、
class Ask
{
public int Id { get; set; }
}
class DestinationDto
{
public Ask Ad { get; set; }
}
class SourceDto
{
public int? Ask_Id { get; set; }
}
その場合は、以下のマッパーを使用してください。
Mapper.CreateMap<SourceDto, DestinationDto>()
.ForMember(dest => dest.Ad, opt => opt.MapFrom(src => src.Ask_Id == null ? null : new Ask { Id = src.Ask_Id.Value }));
var source = new SourceDto { Ask_Id = 1}; // try with null
var destination = Mapper.Map<SourceDto, DestinationDto>(source);