A few days back, I created an entity model using views instead of tables. Since my physical model consisted of Views instead of tables so Entity Designer was not able to infer primary keys/relations etc and I had to create them manually. In this post, I will highlight the steps I took to create a working entity model by hand. Please read at your own risk and feel free to contribute your ideas using the comments section.
Assume we have a JobWBS and a ResourceAssignment view with a One-Many relationship as depicted below:
If we try to create an “ADO.NET Entity Data Model” for the above views, Visual Studio will generate a model similar to this one.
Notice that the designer marked all fields as primary keys. We need to manually edit the generated edmx file by opening it with “XML editor”.
You will also notice the following warnings inside the edmx xml:
Errors Found During Generation:
warning 6002: The table/view 'testdb.dbo.vw_JobWBS' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.


