troubleshooting Question

IQueryable expression output

Avatar of Evan Cutler
Evan CutlerFlag for United States of America asked on
.NET ProgrammingC#
7 Comments1 Solution564 ViewsLast Modified:
I have this code:
start = 0;
        rp = 5;
        sortname = "Title";
        sortorder = "OrderBy";

        IQueryable<Advertisement> ads = (from ad in ct.Advertisements
                                        select ad).Skip(start).Take(rp);

        total = ads.Count();

        ParameterExpression AdParam = Expression.Parameter(typeof(Advertisement), "ad");
        MemberExpression Admbr = Expression.PropertyOrField(AdParam, sortname);
        LambdaExpression adLambda = Expression.Lambda(Admbr, AdParam);

        Type[] exprArgTypes = { ads.ElementType, adLambda.Body.Type };

        MethodCallExpression AdCall = Expression.Call(typeof(Queryable), sortorder, exprArgTypes, ads.Expression, adLambda);

        IQueryable orderedads = ads.Provider.CreateQuery(AdCall);

The code creates a really pretty SQL to be fired.

I need to fire the SQL so I can get a List<Advertisements> filled up, or to have ads requery so I can invoke foreach, and get my data out.

Right now, I have the IQueryable expression output.  what's next?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros