Quelle Klassen:AutoMapper - map Eigenschaft Sammlung
public class ApplicationDriverFormVM
{
public ApplicationDriverAddressFormVM PresentAddress { get; set; }
public List<ApplicationDriverAddressFormVM> PreviousAddresses { get; set; }
}
public class ApplicationDriverAddressFormVM
{
[Required]
[StringLength(256)]
[Display(Name = "Address")]
public string Address { get; set; }
[Required]
[StringLength(256)]
[Display(Name = "City")]
public string City { get; set; }
//.....
}
Zielklassen:
public class ApplicationDriverDomain
{
public List<ApplicationDriverAddressDomain> Addresses { get; set; }
}
public class ApplicationDriverAddressDomain
{
public int Id { get; set; }
public string Address { get; set; }
public string City { get; set; }
//....
public bool IsPresentAddress { get; set; }
}
so möchte ich PresentAddress (ein Objekt) und PreviousAddresses (Sammlung) zu Adressen Eigentum (Sammlung zur Karte), wobei jedes Element die IsPresentAddress-Eigenschaft hat, die true sein muss, wenn es PresentAddress zugeordnet wurde und false für PreviousAddresses-zugeordnete Elemente. Ich versuche, solche Karte Grundregeln zu schreiben:
CreateMap<ViewModels.ApplicationDriverFormVM, ApplicationDriverDomain>();
CreateMap<ViewModels.ApplicationDriverAddressFormVM, ApplicationDriverAddressDomain>();
natürlich funktioniert es nicht richtig. Wie geht es?
Danke. Aber es gibt ein (erstes) zusätzliches leeres Element (4 statt 3. Ich habe die aktuelle Adresse und 2 vorherige Adressen) in result. Warum? Außerdem, wie für die aktuelle Adresse und falsche für vorherige Adressen festgelegt werden? –
@OlegSh Ich habe meine Antwort aktualisiert –