Neutral conditions RRS feed

  • Question

  • Hi:


    I have a method that returns a query to be enumerated later, that method looks like:

    public static IEnumerable<ProjectionClass> GetQuery(DataContext db,       System.Linq.Expressions.Expression<Func<ProjectionClass, bool>> condition)


    var query = db.MyTable.Select(d => new ProjectionClass


                                               Name = d.Name,

                                               Address = d.Address,




          return query;



    Where ProjectionClass is like:

    public class ProjectionClass


    public string Name { get; set;}

    public string Address { get; set;}



    As you can see,  in order to use this method, I have to pass two parameters: the DataContext and a condition in the form of a lambda expression like: p => p.Name.StartsWith(“I”), for example:

    IEnumerable<ProjectionClass> data = GetQuery(db, p => p.Name.StartsWith(“I”));


    In this example, we are querying for those records in the database whose Name property start with “I”.

    Now, my question is: How do I pass a neutral condition?, one that results in all records in the database, like p => p == p, I want one that doesn’t throw a warning like: “Comparison made to same variable”

    Thanks in advance.


    Believe you can do it, and you will!!
    Sunday, July 5, 2009 8:04 PM


  • Simply pass in:

         p => true


    Write LINQ queries interactively -
    • Marked as answer by RalphDev Monday, July 6, 2009 3:11 AM
    Monday, July 6, 2009 1:31 AM