title: IEnumerable to EntityCollection failed mapping with automapper using nested mapping
body: <p>Starting with 2.2.0 I'm having a problem with nasted mapping.</p>
  
  <p>I have two models which I need to map: an EntityObject model (autogenerated by EF from DB) and a simple Data Model.
  EntityObject model contains an EntityCollection property of another EntityObject model type, Data Model contains an IEnumerable of another Data Model type: these fields should also be mapped. As an example:</p>
  
  <pre><code>public class AnotherDataModel
  {
      //Some properties
  }
  
  public class DataModel
      {
          //Some properties
  
          private IEnumerable&lt;AnotherDataModel&gt; anotherDataModel;
          public IEnumerable&lt;AnotherDataModel&gt; AnotherDataModel
          {
                  get { return anotherDataModel ?? (anotherDataModel = new AnotherDataModel[0]); }
                  set { anotherDataModel = value; }
          }
      }
  
  public partial class AnotherModel : EntityObject
  {
          //Some properties
  }
  
  public partial class Model : EntityObject
      {
          //Some properties
  
      public EntityCollection&lt;AnotherModel&gt; AnotherModel
          {
                  get
                  {
                  return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection&lt;AnotherModel&gt;(//relationship settings);
                  }
                  set
                  {
                  if ((value != null))
                      {
                          ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection&lt;AnotherModel&gt;(//relationship settings, value);
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>I need to map DataModel to Model. Both needed maps exist:</p>
  
  <pre><code>Mapper.CreateMap&lt;AnotherDataModel, AnotherModel&gt;();
  Mapper.CreateMap&lt;DataModel, Model&gt;();
  </code></pre>
  
  <p>But while mapping DataModel to Model i'm getting an error on mapping AnotherDataModel to AnotherModel properties:</p>
  
  <p><strong><em>The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during deserialization of an object graph.</em></strong></p>
  
  <p>it works fine on automapper 2.0. I tried UseDestinationValue for this field - but the result is the same.</p>
  
  <p>I also got lots of "collection was of a fixed size" errors on mapping IEnumerable in other places, even though an issue about such trouble was closed, but i've fixed it with custom resolver:</p>
  
  <pre><code>public class EnumerableResolver&lt;TCollectionOfInputType, TCollectionOfOutputType&gt; : 
  ValueResolver&lt;IEnumerable&lt;TCollectionOfInputType&gt;, IEnumerable&lt;TCollectionOfOutputType&gt;&gt;
  {
      public IEnumerable&lt;TCollectionOfOutputType&gt; Resolve(IEnumerable&lt;TCollectionOfInputType&gt; source)
      {
          return this.ResolveCore(source);
      }
  
      protected override IEnumerable&lt;TCollectionOfOutputType&gt; ResolveCore(IEnumerable&lt;TCollectionOfInputType&gt; source)
      {
          return source == null
              ? null
              : source.Select(Mapper.Map&lt;TCollectionOfInputType, TCollectionOfOutputType&gt;);
      }
  </code></pre>
  
  <p>It doesn't work in this case. Also, mapping IEnumerable to EntityCollection while they are not nested - works fine:</p>
  
  <pre><code>Mapper.CreateMap&lt;IEnumerable&lt;AnotherDataModel&gt;, EntityCollection&lt;AnotherModel&gt;&gt;();
  </code></pre>
  
  <p>Any help would be appreciated.</p>