title: Accessing / Using a View Entity Framework 6 Code First approach
body: <p>I have created a SQL Server view which performs some reasonably complex logic on other tables/entities and exposes a series of columns.All I wanted to access this view in entity framework code first approach and when I saw discussion in <a href="https://stackoverflow.com/questions/7461265/how-to-use-views-in-code-first-entity-framework">this</a> I just followed and created a class "FooView.cs" and added it to <code>DbSet&lt;FooView&gt;</code> property in my DbContext class.</p>
  
  <pre><code>     public class FooView
       {
        public string PartNumber { get; set; }
        public string PartType   { get; set; }
       }
       public class CatalogContext : DbContext
       {
         public DbSet&lt;FooView&gt; FooView { get; set; }
       }
  </code></pre>
  
  <p>But when I run my code I get an error saying : EntityType 'FooView' has no key defined. Define the key for this EntityType.</p>
  
  <pre><code>      CatalogContext _db = new CatalogContext();
        var l = _db.FooViews.Select(_ =&gt; _.PartNumber);
  </code></pre>
  
  <p>But all I want it to do is access my view from DB <code>dbo.FooView</code></p>
  
  <p>Easier solution for this problem will be creating a EDMX file and accessing the view, But I do not want to have 2 DB contexts.</p>
  
  <p>I would really appreciate if anyone can help me with it, thanks a lot .</p>