Way to automate setting of MergeOptions
Posted
by Nix
on Stack Overflow
See other posts from Stack Overflow
or by Nix
Published on 2010-04-23T11:35:09Z
Indexed on
2010/04/23
11:43 UTC
Read the original article
Hit count: 388
entity-framework
|.net-3.5-sp1
I am looking for an automated way to iterate over all ObjectQueries and set the merge option to no tracking (read only context). Once i find out how to do it i will be able to generate a default read only context using a T4 template. Is this possible?
For example lets say i have these tables in my object context
SampleContext
- TableA
- TableB
- TableC
I would have to go through and do the below.
SampleContext sc = new SampleContext();
sc.TableA.MergeOption = MergeOption.NoTracking;
sc.TableB.MergeOption = MergeOption.NoTracking;
sc.TableC.MergeOption = MergeOption.NoTracking;
I am trying to find a way to generalize this using object context.
I want to get it down to something like
foreach(var objectQuery : sc){
objectQuery.MergeOption = MergeOption.NoTracking;
}
Preferably I would like to do it using the baseclass(ObjectContext):
ObjectContext baseClass = sc as ObjectContext
var objectQueries = sc.MetadataWorkspace.GetItem("Magic Object Query Option);
But i am not sure i can even get access to the queries. Any help would be appreciated.
© Stack Overflow or respective owner