Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework with oracle views

I have a problem using Entity Framework with oracle views, or views in general. I can easily retrieve data from the views through my Entity, which has views only and no tables, but I can't insert, update, or delete any records. This gives the below error below:

The table/view does not have a primary key defined. The Entity is read-only

This occurs even though all my views have at least one Field having "Entity Key" checked.

Note: I am using VS2013 and EF 6

like image 403
user3665512 Avatar asked Nov 19 '25 13:11

user3665512


1 Answers

Your view needs to be updateable (no joins possible) and must have definded primary key (for entity framework, constraint can be disabled, like shown below).

Example:

CREATE OR REPLACE VIEW MYVIEW ( 

ID, 
<COLUMNS>,

CONSTRAINT UNIQUENAMEFORPKCONSTRAINT PRIMARY KEY (<PK_COLUMN>) DISABLE ) 

AS
SELECT <COLUMNS> FROM <TABLE> WHERE <CONDITIONS>;
like image 70
road242 Avatar answered Nov 22 '25 03:11

road242



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!