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)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s