içeriden nesnelerin listesi ile tek nesneyi Harita Aşağıdaki dto nesne var Sonuç olarakAutomapper:</p> <pre><code>public class PriceDto { public string Ticker {get; set;} public double Open {get; set;} public double Close {get; set;} } </code></pre> <p>kaynak eşyaları: Sadece listeye
public class RemoteData
{
public Security Security { get; set; }
public IList<Prices> Prices{ get; set; }
}
public class Security
{
public string Ticker {get; set;}
}
public class Prices
{
public double Open {get; set;}
public double Close {get; set;}
}
, ben toplanmasını almak istiyorum PriceDto
ürün. Ticker
özelliğinin nasıl eşleneceğini biliyorum. Ama, nasıl doğru Prices
haritaya hiçbir fikrim yok: Bekarım RemoteData
çünkü Ayrıca
CreateMap<RemoteData, PriceDto>()
.ForMember(d => d.Ticker, opt => opt.MapFrom(s => s.Security.Ticker));
, Automapper yapılandırmasını bulamıyorum ama IList<PriceDto>
almak istiyorum: For
var json = await rangeUrl.GetJsonAsync<RemoteData>();
var dtos = _mapper.Map<IList<PriceDto>>(json);
geçici çözüm, RemoteData
yerine PriceDto
Prices
için harita oluşturdu veatamak için foreach
kullanın. Ancak, ben automapper ile nasıl yapılacağını anlamak istiyorum.
Olası kopyası [Bir nesneyi nesne listesine eşlemek için AutoMapper kullanma olanağı var mı?] (Https://stackoverflow.com/questions/18096034/possible-to-use-automapper-to-map-one-object- Nesne-to-list) – Rhumborl