title: Using a View with Entity Framework 5 Code First
body: <p>I have created a SQL Server view which performs some reasonably complex logic on other tables/entities in my model and which exposes a series of columns. All but one of these columns are simple types (bigints, nvarchars etc) but one is a complex entity within my model.</p>
  
  <p>I have created an entity which maps to this view as follows:</p>
  
  <pre><code>public class NetworkSuppliersByClient : Entity, IKeyed&lt;long&gt;
  {
      public long NetworkSuppliersByClientId { get; set; }
  
      public long NetworkId { get; set; }
      public String NetworkName { get; set; }
      public long OwningClientId { get; set; }
      public long ClientId { get; set; }
      public virtual Supplier Supplier { get; set; }
      public bool PublicEntry { get; set; }
  
      public long GetKey ()
      {
          return NetworkSuppliersByClientId;
      }
  }
  </code></pre>
  
  <p>As you can see, the Supplier entry maps to an existing entity within the model, itself being a complex type with other contained entities (aka tables).</p>
  
  <p>The issue that I have is that when I try to read from the view I get the error "<strong><em>The entity type NetworkSuppliersByClient is not part of the model for the current context.</em></strong>".</p>
  
  <p>However, when I try to register the entity with the context as a DbSet I get the error "<strong><em>There is already an object named 'NetworkSuppliersByClients' in the database.</em></strong>" as it tries to create a table with the same name as the already existing view.</p>
  
  <p>Is there any way around this, for example to inhibit EF from trying to create the table at startup, or is there a better way to read from a view?</p>