Derik Whittaker

Syndication

News


Using Entity Framework Profiler to find Undisposed Object Context’s

If you are using Entity Framework, or any other ORM for that matter you need to head over to Hibernating Rhinos and buy a copy of Entity Framework Profiler, the license will pay for itself in no time flat.

When using any ORM, but in our case EF it is recommended, ok I would say required that you dispose or close your Data Context once you are done with your database transitions.  Not closing the context will not immediately bring your system to its knees, but over time as your grow and scale you are going to start noticing memory and performance issues.  Sure, you can let the .Net Garbage collector dispose of your context, but you really should be a responsible developer and clean up after yourself, trust me it is worth the effort.

When using EFProfiler you can very easily determine when you left a context dangling open, all you need to do is look at the timings on the executed statements as seen below.

image

Here is the code which produced the above

Now I am only showing you the creation of this because as you can assume it was NEVER closed.

To close this I could manually call the .Dispose method or I could use a using statement as seen here

By using the Using statement above I am explicitly telling the runtime to close the connection, thus freeing my resources and reducing my over head.  The image below shows the statement now

image

As you can see you can find open connections w/ little ease using Entity Framework profiler.

Till next time,


Posted 03-29-2013 8:17 AM by Derik Whittaker
Filed under:

[Advertisement]

Comments

Social bookmarks wrote re: Using Entity Framework Profiler to find Undisposed Object Context’s
on 04-12-2013 8:29 PM

7W5ZVF Very good blog article.Much thanks again. Want more.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)