Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Entity framework


#1

Is there a way to use Smartinspect to automatically log the .Net Entity Framework SQL queries (like the LinkToSqlAdapter) ?


#2

Hello Rasmus,

SmartInspect doesn’t include an adapter class or plugin for EF, unfortunately.

The Entity Framework does not have any tracing capabilities built in as far as I know. However, there are extensions to add tracing to EF:

http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx
http://code.msdn.microsoft.com/EFProviderWrappers

The extensions support the generic TextWriter class. The SmartInspectLinqToSqlAdapter class for LinqToSql is also a TextWriter-derived class which you could use as a starting point and reference to build a similar adapter class for EF (the source is available in the \source directory of your SmartInspect installation).

You would basically need to implement the Write method to pass the trace messages to a SmartInspect session which in turn would write the messages to a SmartInspect log file or the SmartInspect Console.

Hope this helps. Just let me know in case you have any further questions.

Thanks,
Tobias