Entity Framework 4 - Generating Entities based on Views

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.