ilivewithian
ilivewithian

Reputation: 19702

Automapping Lists

I'm starting to learn AutoMapper and coming up against a couple of minor problems.

Essentially I'm getting null reference exceptions when trying to bind to ILists produced by AutoMapper.

My boot strapping method looks like this:

Mapper.CreateMap<Claimant, ClaimantViewModel>()
                .ForMember(
                        vm => vm.Check, 
                        opt => opt.Ignore());

Mapper.CreateMap<IList<Claimant>, IList<ClaimantViewModel>>();
Mapper.AssertConfigurationIsValid();

Which doesn't look to fancy to me. I then try to call:

dlWAMs.DataSource = Mapper.Map<IList<Claimant>, IList<ClaimantViewModel>(someilist);
dlWAMs.DataBind();

With that I'm getting a null reference exception. If I code my own loop and map the models to a view model one at a time the code runs fine.

What am I doing wrong?

Upvotes: 0

Views: 576

Answers (1)

epitka
epitka

Reputation: 17657

First of all you don't need that second map that creates map from IList to IList, remove it. Than if it does not work, show us your classes.

Upvotes: 1

Related Questions