Goldentp
Goldentp

Reputation: 197

Adding a Read-Only View using Update Model from database

I am trying to add a read only View to the Entity Data Model using the update model from database option in the .edmx file. I have been googling this issue into the ground and every site I go to and question I click on says that I need to add a primary key. I know that adding this view is possible because I have done this before using the same database, I just don't remember how I did it. I can't add a key to the view because it is read-only so that answer won't work for me. I know that this question has been asked before but to be quite honest they all link back to the same questions that do not provide a good answer. I am 100% sure that I can add this view to the entity model and after I figure it out I will post here on how to do it if no one else can tell me how. In the mean time I thought I would ask you guys if you might know how I can add this view to the model. Thanks for your help! Hope you have a great day!

Upvotes: 0

Views: 549

Answers (2)

DotNetDan
DotNetDan

Reputation: 96

Even with a read-only view, it needs PKs (to uniquely identify rows) to properly retrieve from the database.

Also, the PKs need to be non-nullable fields. I've had to add ISNULL(Field, 0) as Field in my Views' select statements.

Upvotes: 1

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

Well, I remember to have faced the same case.

If it's the same :

Open your edmx with an xml editor (Visual Studio, open with...).

You should have a reference to your view in the file, but commented.

If that's still true (that was my case), the solution can be found here : http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/fbc69ed3-dd2e-4308-bbf2-0ce330526a4f

First Solution (adding keys) is ok : you add keys to the model, not to your view. But if you do an update model from database, these changes will be lost...

Upvotes: 1

Related Questions