0
の文字列にタイトルだマップ:idでアイテムを取得し、それは私が2機種持っautomapper
public class Client
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
...
[ForeignKey("CountryId")]
public Country Country { get; set; }
public Guid CountryId { get; set; }
}
と
public class Country
{
public Guid Id { get; set; }
public string Title { get; set; }
}
を、私は、このVMを表示したい:
public class ClientDetailsDto
{
public Guid Id { get; set; }
...
public string Country { get; set; } // Country's title
}
Countryを取得し、それをClientDetailsDtoのstring countryにマップする方法は?私は私のスタートアップクラス(Startup.cs)でAutoMapperを使用してい
:
AutoMapper.Mapper.Initialize(config =>
{
config.CreateMap<Entities.Client, Models.ClientDetailsDto>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
$"{src.LastName} {src.FirstName} {src.Patronym}"))
.ForMember(dest => dest.Age, opt => opt.MapFrom(src =>
src.Birthdate.GetCurrentAge()))
// How to get Country's title and map it to ClientDetailsDto.Country?
}
投稿前に私の問題を解決しようとするのは初めてです:Cと動作しません。 –
問題は何ですか? – lucky
nullを返します。 –