2010-03-25 64 views

回答

0

只有通過黑客使用關係和未分離的實體才能做到這一點。見下文。

YourEntity someEntity = null; 

    RelationshipManager relationshipManager = ((IEntityWithRelationships)someEntity).RelationshipManager; 

    IRelatedEnd relatedEnd = relationshipManager.GetAllRelatedEnds().FirstOrDefault(); 

    ObjectQuery getContext = relatedEnd.CreateSourceQuery() as ObjectQuery; 

    YoutObjectContext c1 = (YourObjectContext)getContext .Context; 

祝你好運。如果你使用上面的代碼,我建議用空檢查保護它。