ASP.Net MVC C# AutoMapper using Where statement
using AutoMapper - is it possible, when mapping a domain to a viewmodel,
to use the where statement, to limit what is mapped to the viewmodel, eg.
I use the following to map the Offer list to the OfferVM viewmodel:
vm.Offers = Mapper.Map<IList<Offer>, IList<OfferVM>>(offers);
However, I only want to map items in the list Offer to OfferVM if a
property on the Offer is set to true, eg:
vm.Offers = Mapper.Map<IList<Offer>, IList<OfferVM>>(offers)
.Where(x => x.RoomName1s==true);
But this gives the error:
Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<FGBS.ViewModels.OfferVM>'
to
'System.Collections.Generic.IList<FGBS.ViewModels.OfferVM>'.
An explicit conversion exists (are you missing a cast?)
Thanks for any help.
Mark
No comments:
Post a Comment