Reputation: 1
I have a regular view in sql server 2008 and I`m using entity framework generate design from database approach. I already know about the keys issues for views in entity framework but that is not my solution. When I query select * from view, it brings out 3 rows which is right, but all the rows are the same and are the first row in the database view.
some help would be very appreciated.
Upvotes: 0
Views: 1417
Reputation: 364259
I already know about the keys issues for views in entity framework but that is not my solution. When I query select * from view, it brings out 3 rows which is right, but all the rows are the same and are the first row in the database view.
What you describe is exactly the problem caused by incorrect key. Your three rows must have unique identification - some column or set of columns must uniquely identify each possible returned record. These columns must be set as entity key in the designer.
You can also avoid this issue by not using change tracking when loading data from the view because returned entities are read-only. You have to use MergeOption.NoTracking
for that ObjectSet
:
context.MyViewEntities.MergeOption = MergeOption.NoTracking;
var data = context.MyViewEntities.ToList();
Upvotes: 6