locked
Dynamically query an object set in EF using LambdaExpression RRS feed

  • Question

  • Hello,

    I am trying to dynamically query Entity Framework, so I'm using the Expression class to put together a LambdaExpression that will be queried against an object set. If I have a reference to LambdaExpression, where I don't have an explicit function defined, is it possible to query against an objectset this way, or is it required to have a generic expression defined (using Expression.Lambda<..>)?

    Thanks.


    http://linkedin.com/in/brianmains
    Tuesday, June 28, 2011 3:41 PM

All replies

  • Hi bmains;

    Not sure what you mean by, "where I don't have an explicit function defined", have you given any thought to using Entity SQL to buils your dynamic query. For example this is an Entity SQL query where SortColunm and SortDirection are string variables.

    var MyQuery = CreateQuery<Customer>
        (
          "SELECT VALUE c FROM Customers as c ORDER BY c." + SortColunm + " " + SortDirection
        ); 
    

     

    Entity SQL Overview
    Entity SQL Language

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, June 28, 2011 4:23 PM