How to get a reference to superior object from Entity object

How to get a reference to superior ObjectContext from EntityObject class?

Answers


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.


Have a look at the following link:

http://blogs.msdn.com/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx

It is like the way that Nix mentioned as an extenxtion to the entity object.


Need Your Help

binary tree functions

binary-tree

how can i clean up this code to so that all the binary tree operations are in there own suite of functions, this code is messy and i want to clean it up

add a new rccord to parallel coordinate chart in d3

javascript d3.js

Hi I am implementing a parallel coordinate chart using D3. This code below is the actual visalization page code. I am getting some information from the user using an input form and I would like to ...