Reputation: 441
In SQL Server Management Studio you can edit a table in the Designer, select two columns, right click and make them a primary key.
Is there a possibility to do this for a view too?
Normally when I have a view in my database, it needs some column to be NOT NULL
. Then in Entity Framework 4
I perform Update Model From Database
(in the .edmx files design view) to import the view, and because one column is NOT NULL
it makes this column a primary key. If there is no column which is NOT NULL
it refuses to import the view into the model.
The problem is, I have a view now where no single column can possibly be the primary key, only two columns combined. How can I make Entity Framework to accept those two columns as primary key.
Or could I maybe add a new column to the view (called Identity maybe) and make this column the primary key? How could I do this?
Upvotes: 0
Views: 875
Reputation: 364369
In EF you can just select your entity in desinger and set any property (or set of properties) to be entity key. Database view cannot have primary key, you can make indexed view but EF will most probably ignore this.
Upvotes: 1