title: Using AutoMapper to map between 2 lists of objects
body: <p>I use <code>AutoMapper</code> to map between my domain model and view model and vice versa.</p>
  
  <p>I normally do my mappings like this in my controller:</p>
  
  <pre><code>// Mapping
  Tutorial tutorial = (Tutorial)tutorialMapper.Map(viewModel, typeof(TutorialEditViewModel), typeof(Tutorial));
  </code></pre>
  
  <p>My tutorial mapper class to handle the above:</p>
  
  <pre><code>public class TutorialMapper : ITutorialMapper
  {
       static TutorialMapper()
       {
            Mapper.CreateMap&lt;TutorialCreateViewModel, Tutorial&gt;();
            Mapper.CreateMap&lt;TutorialEditViewModel, Tutorial&gt;();
            Mapper.CreateMap&lt;Tutorial, TutorialEditViewModel&gt;();
       }
  
       public object Map(object source, Type sourceType, Type destinationType)
       {
            return Mapper.Map(source, sourceType, destinationType);
       }
  }
  </code></pre>
  
  <p>I'm trying to shorten my way of mapping between lists.  I currently do it like this:</p>
  
  <pre><code>IEnumerable&lt;Tutorial&gt; tutorialsList = tutorialService.GetAll();
  IEnumerable&lt;TutorialListViewModel&gt; tutorialListViewModels =
       from t in tutorialsList
       orderby t.Name
       select new TutorialListViewModel
       {
            Id = t.Id,
            Name = t.Name,
            IsActive = t.IsActive
       };
  </code></pre>
  
  <p>Is it possible to map it soemthing like this?</p>
  
  <p>I know that AutoMapper supports mapping of lists, but how would I implement it into my scenario?</p>
  
  <p>I also tried the following:</p>
  
  <pre><code>IEnumerable&lt;Tutorial&gt; tutorialsList = tutorialService.GetAll();
  IEnumerable&lt;TutorialListViewModel&gt; tutorialListViewModels = (IEnumerable&lt;TutorialListViewModel&gt;)tutorialMapper.Map(tutorialsList, typeof(IEnumerable&lt;Tutorial&gt;), typeof(IEnumerable&lt;TutorialListViewModel&gt;));
  </code></pre>
  
  <p>But if there are no items in tutorialsList then I get the following error:</p>
  
  <pre><code>{"The entity type Tutorial is not part of the model for the current context."}
  </code></pre>