title: Does WPF DataGrid Implicitly Convert IEnumerable<x> to List<x> When Binding?
body: <p>Most of my question is in the title: Does WPF DataGrid Implicitly Convert IEnumerable&lt;X> ItemsSource to List&lt;x>? </p>
  
  <p>I have a WPF, using MVVM, etc. ViewModel property is defined as ...</p>
  
  <pre><code>    private IEnumerable&lt;Plan&gt; _PlanListItems;
      public IEnumerable&lt;Plan&gt; PlanListItems
      {
          get { return _PlanListItems; }
          protected set { RaiseAndSetIfChanged(ref _PlanListItems, value); }
      }
  
      // ...
      // in some method
      OpenPlanItems = await service.GetAllPlansAsync();
  </code></pre>
  
  <p>In service ... </p>
  
  <pre><code>    public IEnumerable&lt;Plan&gt; GetAllPlans()
      {
          using (MyEntities ent = new MyEntities())
          {
              return (from a in ent.DbPlans select a)
                  .AsEnumerable()
                  .Select(o =&gt; o.Convert());   // Does some stuff to convert DbPlan entity into Plan class
          }
      }
  
      public async Task&lt;IEnumerable&lt;Plan&gt;&gt; GetAllPlansAsync()
      {
          return await Task.Run(() =&gt; GetAllPlans());
      }
  </code></pre>
  
  <p>In XAML ...</p>
  
  <pre><code>    &lt;DataGrid ItemsSource="{Binding PlanListItems}"  ...&gt;
  </code></pre>
  
  <p>This throws an exception: The operation cannot be completed because the DbContext has been disposed error. <a href="https://stackoverflow.com/questions/13617698">Another question</a> indicates a cause could be due to late execution on the IEnumerable object (i.e. trying to enumerate after the context has been disposed). </p>
  
  <p>Additionally, I have similar code that has a .ToList() conversion inside a method similar to GetAllPlans(). Something like this, but not the actual code:</p>
  
  <pre><code>    public List&lt;Plan&gt; GetAllPlans()
      {
          using (MyEntities ent = new MyEntities())
          {
              return (from a in ent.DbPlans select a)
                  .AsEnumerable()
                  .Select(o =&gt; o.Convert()).ToList();   // Does some stuff to convert ...
          }
      }
  </code></pre>
  
  <p>It turned out to be a slow method (>5 seconds). When I removed the .ToList() conversion, it dropped the time to &lt;0.2 seconds, but the inefficiency returned (and almost the exact same duration) when I bind the result to a DataGrid. </p>
  
  <p>This leads me to believe that WPF DataGrid implicitly converts IEnumerable bound items to a List as part of the binding process. Is that true? And if so, is there a way to avoid the implicit conversion?</p>