Capture SQL Generated from Linq
Capture SQL Generated from Linq
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.
Re: Capture SQL Generated from Linq
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.
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.