views:

51

answers:

2

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!

+1  A: 

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.

Jeremy Child
Yep, a hidden gem. I created an extension method for this, as i couldnt be bothered casting the IQueryable to the ObjectQuery. :)
RPM1984
A: 

Use SQL profiler?... assuming you mean SQL Server

gbn