I'm looking at analysing the performance of the SQL generated from Entity Framework 1, using MS SQL 2008.
When I run a trace in SQL Server Profiler 2008, I noticed something that I didn't expect. For each query that gets executed, I get two RPC:Completed
statements, separated by an exec sp_reset_connection statement
. Is this the expected behavior?
Visual Studio Output NET Core make it pretty easy to output the SQL when debugging. You can set the logging level for Microsoft to “Information”. Then you can view the SQL in the output log when running in debug mode from Visual Studio. The SQL will then be visible in the Output panel.
EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.
Answer: Yes
It turns out that it was a "feature" within AutoMapper that was causing my issue.
See here: When Mapping an IQueryable I see the database getting hit twice in my profiler.
Unfortunately because I'm using version 1.1 (.net 3.5) this doesn't look like it's going to get fixed.
Solution: call .ToList()
on the IQueryable object before passing it into the Mapper.Map()
method. Allowing the Mapper to enumerate the object causes a double execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With