none
PredicateBuilder 'OR' Question RRS feed

  • Question

  • Hi All,

    I'm using Subsonic 3.0 along with the PredicateBuilder class [http://www.albahari.com/nutshell/predicatebuilder.aspx] and am trying to get the following code to work:

     

          CF1dataSQLConnectionString.Data.CF1dataSQLConnectionStringDB db = new CF1dataSQLConnectionString.Data.CF1dataSQLConnectionStringDB();
    
          var query = from p in db.EventHistories
                select p;
    
          var predicate = PredicateBuilder.False<CF1dataSQLConnectionString.Data.EventHistory>();
          predicate = predicate.Or(p => p.EventGroup.Contains("Backup Data"));
          predicate = predicate.Or(p => p.EventGroup.Contains("Update Settings"));
    
          query = query.Where(predicate);
    
          dGEventManager.DataSource = query.ToList();

     

    Instead, I receive the following error: "The member 'EventGroup' is not supported"

    I'm not quite sure what I'm doing wrong...

    Thanks!

     

    Tuesday, November 2, 2010 2:33 PM

Answers

  • After some time with this problem I was able to figure it out. Here's the code I ended up using in cause anyone else has the same problem.

     

          var query = from p in db.EventHistories
                select p;
    
          var predicate = PredicateBuilder.False<CF1dataSQLConnectionString.Data.EventHistory>();
          foreach (var word in cLBEventSelector.CheckedItems)
          {
            string temp = word.ToString();
            predicate = predicate.Or(p => p.EventGroup.Contains(temp));
          }
    
          dGEventManager.DataSource = query.Where(predicate.Compile()).ToList();

    Thanks!

     

    • Marked as answer by liurong luo Thursday, November 4, 2010 1:56 AM
    Tuesday, November 2, 2010 6:53 PM

All replies

  • After some time with this problem I was able to figure it out. Here's the code I ended up using in cause anyone else has the same problem.

     

          var query = from p in db.EventHistories
                select p;
    
          var predicate = PredicateBuilder.False<CF1dataSQLConnectionString.Data.EventHistory>();
          foreach (var word in cLBEventSelector.CheckedItems)
          {
            string temp = word.ToString();
            predicate = predicate.Or(p => p.EventGroup.Contains(temp));
          }
    
          dGEventManager.DataSource = query.Where(predicate.Compile()).ToList();

    Thanks!

     

    • Marked as answer by liurong luo Thursday, November 4, 2010 1:56 AM
    Tuesday, November 2, 2010 6:53 PM
  • Great! Thanks for sharing your solution. This can benefit our community members!

    Cheers!


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Thursday, November 4, 2010 1:56 AM