How to get SQL statement generated by LINQ to Entity

Simply cast your result to System.Data.Objects.ObjectQuery and then use ToTraceString() method.

((System.Data.Objects.ObjectQuery) result).ToTraceString()

Użycie CompiledQuery w Entity Framework

private static IList<byte> OpenStatuses = new List<byte>(new byte[] { (byte)Open, (byte)InProgress });

private static readonly Func<db, byte, long, IQueryable<RequestEF>> GetQuery =
            CompiledQuery.Compile<db, byte, long, IQueryable<RequestEF>>(
                (ctx, salesId, assignedId) =>
                    from csr in ctx.CSR
                    join sales in ctx.SALES
                         on csr.SalesId equals salesOrg.SalesId
                    join customer in ctx.CUSTOMER
                         on csr.CustomerId equals customer.CustomerId
                    join user in ctx.USER
                         on csr.CreatedByUserId equals user.UserId
                    join ct in ctx.CALL
                         on csr.CallId equals ct.Id into joinedCsrCall
                    from callType in joinedCsrCall.DefaultIfEmpty()
                    join uAg in ctx.GROUP
                         on csr.AssignedId equals uAg.Id into joinedEmpDept
                    from group in joinedEmpDept.DefaultIfEmpty()
                    where csr.SalesId == salesId && csr.AssignedId == assignedId &&
                    select new RequestEF
                        Group = group,
                        CSR = csr,
                        Sales = sales,
                        Customer = customer,
                        User = user,
                        Call = call

I wywołanie skompilowanego zapytania:

GetQuery.Invoke(db, salesId, assignedId)