none
PredicateBuilder AND query question RRS feed

  • Question

  • Database table contains this data

    OBJECTID|SURVEYID|FIELDID|VALUE1|VALUE2
    1,100,320,2,3
    2,100,321,2,2
    3,101,320,2,4
    4,101,321,1,1

    I want to build a query to get records where FIELDID=320 AND FIELDID=321.

    Here's what I've tried but doesn't return any records.


            var predicate = PredicateBuilder.True<SurveyDetail>();
            predicate = predicate.And(p => p.FIELDID == 320);
            predicate = predicate.And(p => p.FIELDID == 321);
    
            SurveyDataContext db = new SurveyDataContext();
    
            var query = from s in db.SurveyDetails.Where(predicate)
                        select s;
    GridView1.DataSource = query; GridView1.DataBind();


    How would I do this using PredicateBuilder?
    • Edited by dm80 Tuesday, June 2, 2009 8:21 PM
    Tuesday, June 2, 2009 8:20 PM

Answers

  • Are you sure you don't want an OR?  FIELDID cannot be 320 and 321 at the same time, so if things are working correctly, you should return empty.
    • Marked as answer by dm80 Tuesday, June 2, 2009 9:36 PM
    Tuesday, June 2, 2009 9:16 PM

All replies

  • Are you sure you don't want an OR?  FIELDID cannot be 320 and 321 at the same time, so if things are working correctly, you should return empty.
    • Marked as answer by dm80 Tuesday, June 2, 2009 9:36 PM
    Tuesday, June 2, 2009 9:16 PM
  • Ah ha.  I knew it was something simple.  You're absolutely right - how can FIELDID be equal to 320 and 321.  An OR'ed query is probably what I need.

    Tuesday, June 2, 2009 9:30 PM