title: Entity Framework 6 mapping a custom SQL query to an Entity
body: <p>I am very new to ASP.NET MVC and Entity Framework at the moment. I've been working with it for about 3 months at the current moment in time.</p>
  <p>I have an ASP.NET MVC 5 application that's running Entity Framework 6. This is a code first approach from an existing database with auto migrations enabled so all of my Entity classes are auto generated. I am trying to add a view to my MVC application that returns a specific result set. Currently the previous developer has the application set up to only accept an Entity class to display data to a DataTable <a href="http://datatables.net" rel="nofollow noreferrer" title="DataTables.net">DataTables.net</a>. To clarify further:</p>
  <p>I have two Entity tables in my model that are tables in MySQL.</p>
  <pre><code>| Samples           | SampleLocation |
  |:------------------|---------------:|
  | Id                |     LocationId |        
  | DateAssigned      |           Name |      
  | CheckedInDate     |           Size |         
  | SampleLocationId  |                |        
  | ...etc            |         ...etc |          
  </code></pre>
  <p>What I'm trying to accomplish is querying both tables and returning the results to my MVC application in a view. From there run an Update and update a couple of columns in the Samples table. Below is the roughly the query that returns the results I need.</p>
  <pre><code>SELECT Samples.Id, samples.CheckedInDate, SampleLocation.Name, SampleLocation.Size, 
  SampleLocation.LocationId 
  FROM (Samples join SampleLocation 
  ON ((Samples.SampleLocationId = SampleLocation.LocationId))) 
  WHERE  isnull(samples.CheckedInDate) ORDER BY samples.Id
  </code></pre>
  <p>From the research that I have done there are a few ways to accomplish this. The ways that I've tried that would give me a class I could use are creating a stored procedure and then updating the model - this breaks the model and unmaps every single entity in the model. I have tried creating a view with the query to add to the model - but this breaks it as well and unmaps everything. I later found out that this is a bug.</p>
  <p>So my question is, how can I map a query to an Entity that return results to a view? Is there a better way to go about this?</p>