Retrieving the SQL generated by the Entity Provider for Teradata

Blog
The best minds from Teradata, our partners, and customers blog about whatever takes their fancy.
Teradata Employee

This blog will show you how to retrieve the SQL statement that is generated by the Entity Provider when it processes a  LINQ to Entities or Entity Sql statement.  LinqPad will be used to show you how this can be done.  The blog Using LINQPad to Access Teradata shows how to setup LINQPad to access Teradata.

LINQPad is only able to show the SQL statement that corresponds to a LINQ to Entities or Entity Sql statement when executed against SQL Server.

In addition to executing LINQ to Entities and Entity Sql statements, LINQPad can be used to execute C# code.  Here is the program that contains three different examples on how the SQL statement that is generated by the Entity Provider for Teradata can be retrieved:

Example1 contains a LINQ to Entities statement.  Example2 and Example3 both contain an Entity Sql statement.  In Example1 and Example2, the ToTraceString method that is called is contained in the ObjectQuery class.  In example3, the ToTraceString method that is called is contained in the EntityCommand class. 

The SQL statement that is returned is not formatted.