title: Can SQL Server views have primary and foreign keys?
body: <p>Is it possible to define primary and foreign keys for database Views in Microsoft SQL Server Management Studio? How?</p>
  
  <p>I'm trying to create an ADO.NET Entity Data Model to read from four old, poorly-formed database tables that I cannot modify. I've created views of just the data I need.</p>
  
  <p>The four views should map to a simple three-entity EDMX with one many-to-many relationship.</p>
  
  <p>I get this error when creating my Data Model:</p>
  
  <blockquote>
    <p>The table/view '...' does not have a
    primary key defined and no valid
    primary key could be inferred. This
    table/view has been excluded. To use
    the entity you will need to review
    your schema, add the correct keys and
    uncomment it.</p>
  </blockquote>
  
  <p>It correctly inferred the primary keys of two views. But failed to do so with the other two.</p>
  
  <p>One of my problem views uses aggregate functions:</p>
  
  <pre><code>SELECT MAX(...) ... GROUP BY ...
  </code></pre>
  
  <p>The other ought to have a compound primary key of two foreign keys.</p>