Best way to show the SQL trace of a LINQ query to Entity Framework 3.5

Best way to show the SQL trace of a LINQ query to Entity Framework 3.5?

I am using ASP.net and EF 3.5.

Dim dbo As Web.Portal.RBMEntities = New Web.Portal.RBMEntities

Dim Query = From RoleAllocations In dbo.RoleAllocations Where RoleAllocations.user_id = _ID And RoleAllocations.expire_date > Today Select RoleAllocations

' Console write the SQL trace???

Thankyou!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I just attempted to do this:

        Dim TraceString As String = TryCast(Query, ObjectQuery).ToTraceString

Which works great and returns the SQL trace of the LINQ statement.

Method 2

Use SQL profiler?… assuming you mean SQL Server

Method 3

Entity Framework Profiler found here http://efprof.com/ does this very elegant.

It is easy to start using, and it also gives some hints on possible “issues” with your queries. It will help you get an understanding about whats going on under the “EF hood”.

It is not free but there is a 30 days trial for it. I would recommend it for EF newbies as it can be confusing to understand the way EF abstracts the database chatter.

The setup is smooth and its lightweight.
Once downloaded, read the “How to use.txt” to get it going.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x