2

When using LINQ to SQL, I can use the DataContext.GetCommand method to get a DbCommand instance for an IQueryable. Now I'm using Entity Framework (code-first, but that shouldn't matter) and I want to get a DbCommand from an IQueryable that I generated against my DbContext.

Is this possible? If so how?

John Bledsoe
  • 17,142
  • 5
  • 42
  • 59

1 Answers1

1

I'm not aware of any method to retrieve DbCommand from linq-to-entities query but you can try to convert the query to ObjectQuery<T> and call its CommandText property.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I'll see what I can do, although [another answer](http://stackoverflow.com/questions/4766122/how-can-i-convert-a-dbqueryt-to-an-objectqueryt#4769245) seems to indicate that I can't get an ObjectQuery from a DbQuery. I'll update if I have any luck. – John Bledsoe Jul 01 '11 at 13:20