How to get a reference to superior ObjectContext from EntityObject class?
Asked
Active
Viewed 443 times
3
-
guessing you moved on from this? – Nix Apr 03 '10 at 16:04
2 Answers
1
Have a look at the following link:
It is like the way that Nix mentioned as an extenxtion to the entity object.

Reza
- 353
- 1
- 2
- 15
0
Only way you can do it is via a hack using relationships, and an entity that is not detached. See below.
YourEntity someEntity = null;
RelationshipManager relationshipManager = ((IEntityWithRelationships)someEntity ).RelationshipManager;
IRelatedEnd relatedEnd = relationshipManager.GetAllRelatedEnds().FirstOrDefault();
ObjectQuery getContext = relatedEnd.CreateSourceQuery() as ObjectQuery;
YoutObjectContext c1 = (YourObjectContext)getContext .Context;
Good luck with it. If you use the code above i recommend protecting it with null checks.

Nix
- 57,072
- 29
- 149
- 198