I have such classes:
public abstract class BookingShoppingCart : SerializableEntity, IShoppingCart
{
protected BookingShoppingCart()
{
Accommodations = new ObservableCollection<RQBooking>();
Packages = new ObservableCollection<RQBooking>();
Splits = new ObservableCollection<RQBookingContainer>();
}
public ObservableCollection<RQBooking> Accommodations { get; set; }
public ObservableCollection<RQBooking> Packages { get; set; }
public ObservableCollection<RQBookingContainer> Splits { get; set; }
public List<RQBooking> AllAccommodationsAndParts
{
get { return Accommodations.Union(Splits.SelectMany(s => s.Bookings)).ToList(); }
}
public List<RQBooking> AllBookedItemsAndParts
{
get { return Accommodations.Union(Packages).Union(Splits.SelectMany(s => s.Bookings)).ToList(); }
}
public decimal AccommodationFeesTotal
{
get { return AllBookedItemsAndParts.Sum(x => (x.RQReservation.FeeRules.Any(r => r.AppliedOn == FeeAppliedOn.Booking)) ? x.RQReservation.FeeRules.Where(r => r.AppliedOn == FeeAppliedOn.Booking).Sum(r => r.Total) : 0); }
}
public decimal AddonsFeesTotal
{
get { return AllAccommodationsAndParts.Sum(x => (x.DefaultRQAddonsOrder.Items.SelectMany(oi => oi.FeeRules).Sum(r => r.Total))); }
}
public decimal AccommodationTotalWithoutFees
{
get { return AllAccommodationsAndParts.Sum(x => x.RQReservation.TotalBooking) + Packages.Sum(x => x.Total); }
}
public decimal AddonsTotalWithoutFees
{
get { return AllAccommodationsAndParts.Sum(x => OrderItemGrouping.ItemsExceptFree(x.DefaultRQAddonsOrder).Sum(o => o.Total)); }
}
public decimal AddonsTotal
{
get { return AddonsTotalWithoutFees + AddonsFeesTotal; }
}
public UserInfoRequest UserInfoRequest { get; set; }
public string Currency { get; set; }
public string BookingDates { get; set; }
public string BookingStartDate { get; set; }
public string BookingStartDateFormat { get; set; }
public string BookingEndDate { get; set; }
public string BookingEndDateFormat { get; set; }
public string BookingNights { get; set; }
public decimal CurrencyExcRate { get; set; }
public abstract decimal Total { get; }
public abstract void Init();
}
public class BookingShoppingCartCreate : BookingShoppingCart
{
public override decimal Total
{
get { return AccommodationTotal + AddonsTotal; }
}
public override void Init()
{
}
}
public class QuoteBookingShoppingCart : BookingShoppingCartCreate
{
}
And I need to cast BookingShoppingCart to QuoteShoppingCart:
public BookingConfirmation ConfirmQuoteWithSession(BookingShoppingCart bookingShoppingCart)
{
var bookingShoppingCartCreate = _mappingEngine.Map<BookingShoppingCartCreate>(bookingShoppingCart);
var quoteShoppingCart = _mappingEngine.Map<QuoteBookingShoppingCart>(bookingShoppingCartCreate);
var confirmResult = _bookingServiceFacade.CreateOrUpdateReservation(quoteShoppingCart, targetPersonID);
}
I created mapper for this:
public class ExampleAutomapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(
configuration =>
{
configuration.AddProfile<QuoteProfile>();
});
Mapper.AssertConfigurationIsValid();
}
public class QuoteProfile : BaseProfile
{
protected override void Configure()
{
CreateMap<BookingShoppingCart, BookingShoppingCartCreate>()
.IgnoreAllNonExisting();
CreateMap<BookingShoppingCartCreate, QuoteBookingShoppingCart>()
.IgnoreAllNonExisting();
}
}
But everytime I get an error:
Missing type map configuration or unsupported mapping.
Mapping types:
BookingShoppingCartCreate -> QuoteBookingShoppingCart
ShoppingCarts.BookingShoppingCarts.BookingShoppingCartCreate -> ShoppingCarts.BookingShoppingCarts.QuoteBookingShoppingCart
Destination path:
QuoteBookingShoppingCart
What's wrong? Mapping from BookingShoppingCart to BookingShoppingCartCreate works, but from BookingShoppingCartCreate to QuoteShoppingCart - no:( I also tried to specify all members with
.ForMember(dest => dest.AccommodationFeesTotal, exp => exp.MapFrom(scc => scc.AccommodationFeesTotal))
and etc, but no result.
QuoteBookingShopingCart. But that's not in your code. How is that supposed to be mapped? What's its type and the corresponding source property's type. AM says those types cannot be mapped and perhaps you need a map between them.Destination path: QuoteBookingShoppingCart.