title: Entity Framework - Select specific columns and return strongly typed without losing cast
body: <p>I'm trying to do something similar to <a href="https://stackoverflow.com/questions/1094931/linq-to-sql-how-to-select-specific-columns-and-return-strongly-typed-list">this post</a> where I don't pull back all columns from a particular entity, however my framework makes use of inheritence and I lose scope of the entity type after it's been cast to an anonymous type. </p>
  
  <p>The structure of my Entity Framework has a base entity called <em>Action</em>.  From here I've created two inherited entities called <em>Event</em> and <em>Activity</em>.  I want to pull back the last X Actions and pass them to my strongly typed view which accepts an Action and from there determines if its an Activity or Event and renders the correct partial view.  </p>
  
  <pre><code>if(Model.GetType() == typeof(Event))
  {
    //render Event view
  }
  else if(Model.GetType() == typeof(Activity))
  {
    //render Activity view
  }
  </code></pre>
  
  <p>I can pull the last 10 as an anonymous type and then cast:</p>
  
  <pre><code>var result = from a in new DataContext().Actions
               where a.UserId == someGuidValue
               select new { a.CreatedOn, a.Summary };
  
  List&lt;Action&gt; list = result.AsEnumerable()
                            .Select(o =&gt; new Action {
                                             CreatedOn = o.CreatedOn, 
                                             Summary = o.Summary
                            }).ToList();
  </code></pre>
  
  <p>However, once I pass the new List of Actions to my strongly typed view it loses scope of whether it's an Activity or an Event since it's been cast as an Action.  My question is, without exposing the discriminator column, is there any way to cast each item to the proper type or am I going about this the wrong way?</p>