New Posts New Posts RSS Feed: Question about PredicateBuilder
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Question about PredicateBuilder

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: Question about PredicateBuilder
    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);

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down