Print Page | Close Window

Question about PredicateBuilder

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2139
Printed Date: 10-Jun-2026 at 5:28pm


Topic: Question about PredicateBuilder
Posted By: BillG
Subject: Question about PredicateBuilder
Date Posted: 09-Sep-2010 at 12:52pm

Here is my FetchMembers method, the user can do a search on members by cardno, ssn, employee #, lastname, firstname. When they click the find button, I put the fields into a query object and pass the object to the fetchmembers methd. I then build the PredicateBuilder. Everything so far works fine. The only other thing I add to the query is that they to have an "Active" status. Now I need to add that they can have an "Active" or "Staff" status. So look at the line in red and how do I add an "or" statement here to pick up ones that have a status of "S" in addition to "A"?  

       List<PredicateDescription> predicateDescriptions = new List<PredicateDescription>();

          PredicateDescription aPredicateDescription;
          if(q.SSN != string.Empty)
          {
              aPredicateDescription = PredicateBuilder.Make(typeof (Member), "SocSecNo", FilterOperator.IsEqualTo,
                                                            q.SSN);
              predicateDescriptions.Add(aPredicateDescription);
          }

          if(q.LastName != string.Empty)
              predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "LastName", FilterOperator.StartsWith, q.LastName));

          if (q.FirstName != string.Empty)
              predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "FirstName", FilterOperator.StartsWith, q.FirstName));

          if (q.EmployeeNo != string.Empty)
              predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "EmployeeNumber", FilterOperator.IsEqualTo, q.EmployeeNo));

          if(q.CardNo != 0)
              predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "CardNo", FilterOperator.IsEqualTo, q.CardNo));

          predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "Status", FilterOperator.IsEqualTo, "A"));

         how do I add a status of "S" here with an or statement.
 
          CompositePredicateDescription aCompositePredicateDescription = PredicateBuilder.And(predicateDescriptions.ToArray());

        IQueryable query = PredicateBuilder.FilterQuery(entityManager.Members, aCompositePredicateDescription);

          IEnumerable results = entityManager.ExecuteQuery(((IEntityQuery) query));

          foreach(Member m in results)
              Members.Add(m);




Print Page | Close Window