2

I am using PredicateBuilder, which means that I am using the AsExpandable extension method. The problem is that I can no longer Trace my SQL queries as the following error is thrown when I try to cast the query to ObjectQuery so that I can do a ObjectQuery.ToTraceString() call on it...

Unable to cast object of type 'LinqKit.ExpandableQuery`1[Genesis.Person]' to type 'System.Data.Objects.ObjectQuery'.

Any Ideas?

Calanus
  • 25,619
  • 25
  • 85
  • 120

3 Answers3

5

I would recommend running a Dump() on your query in LINQPad, and using the SQL tab to see what SQL was generated. Do do this, hook up LINQPad to your Entity Framework context, press F4 to include a reference to LinqKit.dll, and LinqKit as a namespace import. Let me know if you need additional guidance in how to do this.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
  • OK, I'll have a go at this tomorrow when I'm back at work but it seems like a reasonable way to get the SQL out... – Calanus Oct 04 '09 at 17:02
3

Use the following universal PredicateBuilder instead of LinqKit:

http://petemontgomery.wordpress.com/2011/02/10/a-universal-predicatebuilder/

Then ObjectQuery.ToTraceString() will work as expected.

Adam
  • 41
  • 3
1

I'm not familiar with your precise problem but can you not run the trace on the SQL server instead using (eg profiler assuming MSSQL) ?

This would still allow you to see the executed queries and you could restrict it to be just your machine that is recorded...

Basic
  • 26,321
  • 24
  • 115
  • 201