Capture SQL Generated from Linq

Capture SQL Generated from Linq

Postby lhengen » Fri 06 Feb 2015 23:07

Is there a way to capture the SQL generated from LINQ queries short of capturing traffic sent to the RDBMS? This would be useful for learning LINQ by experimentation.
lhengen
 
Posts: 1
Joined: Fri 06 Feb 2015 23:04

Re: Capture SQL Generated from Linq

Postby AlexP » Mon 09 Feb 2015 12:14

hello,

Yes, you can retrieve the text of the last executed SQL query, that was generated according to the LINQ query. For this, you can execute the following code:

type
TDataContextUtil = class(TDataContext)
end;
.....
TDataContextUtil(EntityContext1).QueryCompiler.LastQuery.SQL;
.....

You can samples in the Demo application, in the 'Working with LINQ queries' branch.
AlexP
Devart Team
 
Posts: 5530
Joined: Tue 10 Aug 2010 11:35


Return to EntityDAC