<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx</link><description>Customers often ask how to get from an Entity back to the ObjectContext . 
 Now generally we don’t recommend trying this. But sometimes you really need a way to get to the ObjectContext . 
 For example if you are in method and all you have is the Entity</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#10153152</link><pubDate>Wed, 13 Apr 2011 09:47:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10153152</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Thanks a lot. &lt;/p&gt;
&lt;p&gt;Getting the context of an entity was pretty useful to me, to be able to see if the underlying objectcontext has been disposed (and then handle it accordingly). Thanks for the article.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10153152" width="1" height="1"&gt;</description></item><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#10092502</link><pubDate>Wed, 17 Nov 2010 11:25:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10092502</guid><dc:creator>Michael Smit</dc:creator><description>&lt;p&gt;I have been trying a way to do this for nearly TWO DAYS now and finally came upon your post - AND IT WORKS!!! Thank-you, thank-you, thank-you.&lt;/p&gt;
&lt;p&gt;My scenaria...&lt;/p&gt;
&lt;p&gt;I have a bunch of navigation properties that each have the TypeConverter attribute attached to the relevant partial classes to be able to perform combobox lookups in a PropertyGrid. I needed to be able to find out the ObjectContext from the context.Instance passed in at GetStandardValues so I could do the lookup.&lt;/p&gt;
&lt;p&gt;My initial solution was to create a static property in my application that returned the ObjectContext but after lots of reading on EF4 (I am new to it) I have come to the conclusion it is not wise to keep the ObjectContext alive for the life of the application.&lt;/p&gt;
&lt;p&gt;So I wanted to create an ObjectContext per form and dispose it when the form closes, but then had no way to access the same ObjectContext for lookup queries for the navigation properties. &amp;nbsp;And I could not create a new one as you get the good old &amp;quot;different contexts&amp;quot; when a user selects a different item from the combobox.&lt;/p&gt;
&lt;p&gt;But... Now all is working perfect. You solution is perfect. Thanks BIG time :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10092502" width="1" height="1"&gt;</description></item><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#9941718</link><pubDate>Mon, 28 Dec 2009 21:15:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9941718</guid><dc:creator>Manoj</dc:creator><description>&lt;p&gt;A related issue is that once an entity is detached from context, it loses all the relationship. This is due to the fact that the relationships are tightly coupled to EF. Hopefully EF2 addresses this in a more POCO-friendly fashion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9941718" width="1" height="1"&gt;</description></item><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#9894361</link><pubDate>Fri, 11 Sep 2009 22:56:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9894361</guid><dc:creator>AlexY</dc:creator><description>&lt;p&gt;Thanks a lot for your tips.&lt;/p&gt;
&lt;p&gt;I realy enjoy your blog.&lt;/p&gt;
&lt;p&gt;Easy Peasy is not not sometimes easy ;-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9894361" width="1" height="1"&gt;</description></item><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#9727849</link><pubDate>Fri, 12 Jun 2009 00:23:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9727849</guid><dc:creator>Alex D James</dc:creator><description>&lt;p&gt;Bingo&lt;/p&gt;
&lt;p&gt;We are thinking about adding something, probably a static method on ObjectContext&lt;/p&gt;
&lt;p&gt;i.e. &lt;/p&gt;
&lt;p&gt;ObjectContext context = ObjectContext.GetContext(entity);&lt;/p&gt;
&lt;p&gt;But we need to weigh that up against a lot of other competing ideas, so it might not make it.&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9727849" width="1" height="1"&gt;</description></item><item><title>re: Tip 24 – How to get the ObjectContext from an Entity</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#9727816</link><pubDate>Fri, 12 Jun 2009 00:11:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9727816</guid><dc:creator>Bingo</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Will the next release (.NET 4??) of Entity Framework provide this in a more fundamental fashion.&lt;/p&gt;
&lt;p&gt;Maybe as a property like EntityObject.ObjectContext?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9727816" width="1" height="1"&gt;</description></item><item><title>Meta-Me : Entity Framework Tips</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx#9709062</link><pubDate>Mon, 08 Jun 2009 21:44:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9709062</guid><dc:creator>Meta-Me : Entity Framework Tips</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/alexj/archive/2009/03/26/index-of-tips.aspx"&gt;http://blogs.msdn.com/alexj/archive/2009/03/26/index-of-tips.aspx&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9709062" width="1" height="1"&gt;</description></item></channel></rss>