I have to use a View with the EF but, when I import it, the primary key of the view is displayed incorrectly and for some reason I can't change it.
Asked
Active
Viewed 2.4k times
2
-
1possible duplicate of [Entity Framework and Sql Server view question](http://stackoverflow.com/questions/1013333/entity-framework-and-sql-server-view-question) – Michael Maddox Sep 15 '11 at 14:42
3 Answers
7
Appears to be a known issue - see this other StackOverflow question and its answers:
Entity Framework and SQL Server View
Marc
3
I had a similar problem when i wanted to do a group by in a view that was not easy in linq but ended up not working. What worked for me was to specifically change the entity key in Entity Framework designer to a int column that is unique. If it doesnt exist then create a simple incremented int field in your view definition and use that as your key.

Sergey Glotov
- 20,200
- 11
- 84
- 98

Mark
- 31
- 1
0
In my experience the entity keys on a View are defined using the primary keys of the view (from the select clause).
If you have multiple tables in the view, you must select the primary key, not the foreign key, to see it as an entity key.

James Skemp
- 8,018
- 9
- 64
- 107

Davide Icardi
- 11,919
- 8
- 56
- 77