How to get a link to an enhanced object from an Entity object

How to get a link to an improved ObjectContext from the EntityObject class?

+3
source share
2 answers

Only in this way can you do this using a hack, using relationships, and an object 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 to you. If you use the code above, I recommend protecting it with null checks.

0
source

Take 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

This is similar to how Nix is ​​referred to as extenxtion for an entity object.

+1
source

All Articles