title: Cast() exception: LINQ to Entities only supports casting EDM primitive or enumeration types
body: <p>I want to display some entity named <code>CriminalEvent</code> in a general-purpose MVC view I wrote. The view requires that the Model pass to it shall implement the <code>IDataModel</code> interface. Now, <code>CriminalEvent</code> has the properties to implement this interface but under a different name and I cannot change it.</p>
  
  <p>So in my code I inherited <code>CriminalEvent</code> and my derived class (also called CriminalEvent, stupid I guess but allows me to avoid many code changes...) has explicit interface code:</p>
  
  <pre><code>Using ViewApp;
  public interface IDataModel
  {
      int ID { get; set; }
      int CriminalEventID { get; set; }
  }
  
  public class ViewCriminalEvent : AIM.Police.DB.CriminalEvent, IDataModel
  {
      int IDataModel.ID
      {
          get { return CriminalEventID; }
          set { CriminalEventID = value; }
      }
  }
  </code></pre>
  
  <p>(I know, in this case the interface's ID property equals CriminalEventID, it's Ok)</p>
  
  <p>I expected to be able to read the <code>AIM.Police.DB.CriminalEvent</code> Entities and populate my view model by Linq to Entities Cast()ing them to the derived <code>CriminalEvent</code>, like this:</p>
  
  <p>The view model (I need to populate the <code>CriminalEvents</code> property):</p>
  
  <pre><code>Using ViewApp;
  public class CriminalEventMainViewModel
  {
      public IEnumerable&lt;IDataModel&gt; CriminalEvents { get; set; }
      public IDataModel SelectedEntity { get; set; }
  
      public string SubEntityDisplayName { get; set; }
  
      public IEnumerable&lt;IDataModel&gt; SubEntityCollection { get; set; }
      public IDataModel SelectedSubEntity { get; set; }
  }
  </code></pre>
  
  <p>and the Controller code:</p>
  
  <pre><code>Using ViewApp;    
  private ViewResult CriminalEventIndexView(CriminalEvent selectedCriminalEvent = null)
  {
      CriminalEventMainViewModel viewModel =
          new CriminalEventMainViewModel();
  
      using (var db1 = new AIM.Police.DB.InvestigationContext(lazyLoadingEnabled: false))
      {
          viewModel.CriminalEvents = db1.CriminalEvents.Cast&lt;ViewCriminalEvent&gt;().ToList(); // THIS LINE THROWS THE EXCEPTION
          viewModel.SelectedEntity = selectedCriminalEvent;
      }
      return View("Index", (object)viewModel);
  }
  </code></pre>
  
  <p>Note both the original <code>CriminalEvent</code> class and the <code>InvestigationContext</code> are found in the AIM.Police.DB dll that I cannot touch</p>
  
  <p>The Error:</p>
  
  <p><code>Unable to cast the type 'AIM.Police.DB.CriminalEvent' to type 'InvestigationSimulator.Models.CriminalEvent'. LINQ to Entities only supports casting EDM primitive or enumeration types.</code></p>
  
  <p>Why do I get this error?
  Remarks on my approach are always welcome.. </p>