Read only data context

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
ralovets
Posts: 9
Joined: Tue 01 Nov 2016 17:15

Read only data context

Post by ralovets » Fri 04 Sep 2020 09:45

Hi.

I was trying to make my data context read only. Meaning that we can only query data from it, but not submit.
I found property ObjectTrackingEnabled, but I can't find a way of setting it to false by default.
I want to avoid doing
using (var db= new MyDataContext())
{
db.ObjectTrackingEnabled = false;
....
}
because it can be easily forgotten.
it seems that I can only set it to false during code generation, but that means changing default template and if I ever upgrade to a new version, my template will need to be updated manually or remain old, which is also not ideal.


any other ways i can make my dataContext read only?


I use LinqConnectContextModel

Thanks.
Olga

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

Re: Read only data context

Post by Shalex » Tue 08 Sep 2020 09:29

We recommend you to set this property in a partial class of your DataContext. There is a partial method OnCreated() called in all constuctors. You can implement the OnCreated() method in a partial class and put your code into it.

ralovets
Posts: 9
Joined: Tue 01 Nov 2016 17:15

Re: Read only data context

Post by ralovets » Fri 11 Dec 2020 15:50

sorry, only seeing it now. Never got notifications by email
Will do that thanks!

Post Reply