Entity Framework 4 - Generating Entities based on Views

Posted by geekrutherford on Geeks with Blogs See other posts from Geeks with Blogs or by geekrutherford
Published on Tue, 28 Jun 2011 08:13:53 GMT Indexed on 2011/06/28 16:23 UTC
Read the original article Hit count: 223

Filed under:

Just a quick post regarding a common issue and fix...

When attempting to add a view as an entity to your model the EF generator may complain that it is unable to find or infer a primary key on your view. As a result, it will not add it to the model.

The quick fix is to add the following to which ever column you wish to be the primary key within your view:

ISNLL(TableA.ColumnA, -999) myPrimaryKeyColumnName

Adding this will allow the EF generator to infer the primary key and add the view as an entity to your model.

© Geeks with Blogs or respective owner