Common Issues
Unable to cast ProfiledConnection to SqlConnection
If you try to cast IDbConnection to SqlConnection in your code, you will get an unable to cast ProfiledConnection to SqlConnection exception when using the Entity Framework profiler. This is because that when you call EntityFrameworkProfiler.Initialize() method, we replace the default DbProviderFactory with our own ProfiledDbProviderFactory.
The solution for that is to not cast IDbConnection to SqlConnection, but to DbConnection. It's better practice to not assume in your code that you know the DbConnection type, and always try to use the base IDbConnection and DbConnectino base classes.
The profiler shows the session but without any statements
If you try to run a program that exist very fast, you may see the session in the profiler without any log statements. This is because that the profiler didn't get the chance yet to log the statements because your application already exits. To solve this, you can force the profiler the get all the statements by adding the following line at the end of your code:
ProfilerInfrastructure.FlushAllMessages();