title: Using an SQL View from an Entity Framework Code First version 5
body: <p>I am developing a contact log in a website using VS 2010, MVC3 and EF 5 - the entities are created using code first. The data is stored in an SQL Server 2008 R2 set of databases. I want to display a summary of the contact log and have created a view.</p>
  
  <pre><code>CREATE VIEW dbo.ContactLogSummaries
  
  AS
  
  SELECT
      CLE.ContactLogEntryID,
      CLE.CaseID,
      'Test' AS ContactName,
      EU.UserName As OfficeUser,
      CLE.DateAndTimeOfContact,
      CLC.Category,
      CLE.ContactDetails
  
  FROM
      ContactLogEntries AS CLE
      JOIN
      ContactLogCategories AS CLC
      ON CLE.ContactLogCategoryID = CLC.ContactLogCategoryID
      JOIN
      Control.dbo.EndUsers AS EU
      ON CLE.UserID = EU.EnduserID
  </code></pre>
  
  <p>There are two entities in the Contact Log database (<code>ContactLogEntries</code> and <code>ContactLogCategories</code>) and a database first entity <code>Control.dbo.EndUsers</code> in another database. The contact log could contain a large number of records. I want to be able to display just the records for a specific case.</p>
  
  <p>My question is in two parts:</p>
  
  <ol>
  <li>Can I use the SQL view directly to display a summary on a web page (perhaps by reading it into a class)</li>
  <li>Can I create a code first object equivalent to the SQL view.</li>
  </ol>