NullReference
NullReference

Reputation: 4484

Does Value Injecter map collection properties?

I'm trying to map a collection of EntityFramework objects with a collection of view models.

 public class Channel
{
    public Guid Id { get; set; }

    public string Name { get; set; }

    public IEnumerable<Report> Reports { get; set; }
}

public class ChannelListViewModel
{
    public Guid Id { get; set; }

    public string Name { get; set; }

    public IEnumerable<Report> Reports { get; set; }
}

Using the code below the Reports list is not being mapped. What am I doing wrong?

 IList<ChannelListViewModel> viewModelList = channelList.Select(x => new ChannelListViewModel().InjectFrom(x)).Cast<ChannelListViewModel>().ToList();

Upvotes: 4

Views: 2682

Answers (2)

Omu
Omu

Reputation: 71198

there's an automapper simulation which does that:

http://valueinjecter.codeplex.com/releases/view/60311#DownloadId=318259

you can download it and see how collections are mapped automatically

here's the article: http://valueinjecter.codeplex.com/wikipage?title=Automapper%20Simulation&referringTitle=Home

you can see the unit tests there

Upvotes: 1

danludwig
danludwig

Reputation: 47375

No, not by default, you have to use a custom injecter. This is why I switched back to automapper after trying out valueinjecter. How to map lists with ValueInjector

Upvotes: 3

Related Questions