Reputation: 443
I have a long code line to create a view. For Entity framework to work with this view I need a primary key.
How can I select the column as a primary key?
I've tried this;
dstchannel,billsec,disposition,accountcode, uniqueid as PRIMARY KEY,cnam, callRateImport.Description, callRateImport.Code, callRateImport.Day FROM callLogImport
LEFT JOIN callRateImport ON
uniqueid as PRIMARY KEY.
The other method I tried (to alter view and create primary key) works, but it has to be done before the view is created..
Upvotes: 2
Views: 5500
Reputation: 13865
You cannot create primary keys on the view itself.
To get around the no primary key issue, you can create a unique column that the entity framework will pick up and use.
ISNULL(CAST((row_number() OVER (ORDER BY <columnName>)) AS int), 0) AS ID
So:
SELECT ISNULL(CAST((row_number() OVER (ORDER BY uniqueid)) AS int), 0) AS ID, dstchannel,billsec,disposition,accountcode, uniqueid,cnam, callRateImport.Description, callRateImport.Code, callRateImport.Day FROM callLogImport
LEFT JOIN callRateImport ON ....
Upvotes: 2