Using View with Linked Server (Oracle) on Entity Framework (.NET)

One of the issue I came across on Entity Framework was pulling a view that consist of a linked server table (Oracle). When I added the view, I was getting the following error. "The table/view LINKED_SERVER_VIEW does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it." I needed this view as readonly. Only solution that worked was using ISNULL to define a primary key on the view. You will have to create a view like this for Entity Framework to understand the primary key. CREATE VIEW LINKED_SERVER_VIEW AS SELECT ISNULL(PRIMAYKEYCOLUMN, 0) as COL1, OTHERCOLUMN from LINKEDSERVER..SCHEMA.TABLENAME I believe the best approach is to actually fix the table or the model itself and add an actual primary key. However, sometime you will have to work on a database that a client does not want to change and you will have to deal with issues like this. Hope this solution works for you. If you have better solution, feel free to comment.
FacebookTwitterGoogle+Share

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*