postgres updatable view

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
GregP
Posts: 2
Joined: Wed 25 Mar 2020 17:50

postgres updatable view

Post by GregP » Sun 29 Mar 2020 02:11

I am a new user of dotconnect and was curious if updatable views are supported?
I have not been able to get them to update to database using the datacontext.(gridview -> bindingsource -> datacontext.SubmitChanges) in a simple test project. The views do update to database as expected when tested in the GUI of DBeaver and DbForge as well as in SQL. I tried a simple view which should be automatic and a view with a couple joins. (For the more complex view I implemented a function using INSERT INTO ... ON CONFLICT and triggers using INSTEAD OF for the upserts and deletes.)

GregP
Posts: 2
Joined: Wed 25 Mar 2020 17:50

Re: postgres updatable view

Post by GregP » Sun 29 Mar 2020 22:24

I think I solved the issue myself. The problem seems to occur because the Linq-To-SQL entity automatically generated by a View does not have an Entity Key defined by default -- unlike a Table.

It is curious that Visual Studio did not produce an error when I tried an upsert on the View. I would have expected to see a "System.InvalidOperationException: Can't perform Create, Update or Delete operations on ... does not have identity members" error.

The solution is to open the DataContext diagram for the View in Entity Developer, select the key, go to Properties and toggle Entity Key to True. Now, if the upsert on the view works in dbForge, it should then work in c# .net.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: postgres updatable view

Post by Shalex » Tue 31 Mar 2020 16:23

Thank you for sharing your experience.

JIC: you can use the dbMonitor tool for tracing database activity for debug purpose.

Post Reply