Tracing linq query in sql format c#

Linq query trace in sql format c#

Tracing of Linq to Entities query,
This is for "Linq-to-Entities"
// In Linq
Entities _ent = new Entities();
var obj = from _e in _ent.Employees
          select _e;

// Now Trace linq query
// using System.Data.Objects;
ObjectQuery oqt = (ObjectQuery)obj;
String str = oqt.ToTraceString();

// In SQL format
SELECT 
[Extent1].[TrxnId] AS [TrxnId],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[MiddleName] AS [MiddleName],
[Extent1].[LastName] AS [LastName]
[Extent1].[Deleted] AS [Deleted]
FROM [dbo].[Employees] AS [Extent1]
Tracing linq query in sql format c# Tracing linq query in sql format c# Reviewed by Bhaumik Patel on 7:34 PM Rating: 5