Page 1 of 1

Read only data context

Posted: Fri 04 Sep 2020 09:45
by ralovets
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

Re: Read only data context

Posted: Tue 08 Sep 2020 09:29
by Shalex
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.

Re: Read only data context

Posted: Fri 11 Dec 2020 15:50
by ralovets
sorry, only seeing it now. Never got notifications by email
Will do that thanks!