New Posts New Posts RSS Feed: Compile error on ExecuteAsynch method
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Compile error on ExecuteAsynch method

 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: Compile error on ExecuteAsynch method
    Posted: 26-Oct-2010 at 2:07pm
    I am passing a query object to my GetMembers() method that holds a variable number of search parameters. After building the query with PredicateBuilder, I want to execute the query asynchronously and in the same method use lambda statements to fill the collection instead of using a callback operation. I am getting a compile error on the ExecuteAsynch method. How do I write this method correctly? It is the line in blue at the bottom of the method.
   
       public ObservableCollection<Member> GetMembers(MemberQO q)
        {
            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));

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

            if (q.Office != string.Empty)
                predicateDescriptions.Add(PredicateBuilder.Make(typeof(Member), "Office", FilterOperator.IsEqualTo, q.Office));
      
     CompositePredicateDescription aCompositePredicateDescription = PredicateBuilder.And(predicateDescriptions.ToArray());

            var query = PredicateBuilder.FilterQuery(Mgr.Members, aCompositePredicateDescription);

           query.ExecuteAsync<Member>(op => op.Results.ForEach(Members.Add));
           return Members;
     }


Back to Top
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 Posted: 26-Oct-2010 at 2:25pm
I don't know if these changes get me any closer to the solution. The compile error is still the same statement but it doesn't like the ForEach statment as it doesn't belong to op.Results


            IEntityQuery query = (IEntityQuery)PredicateBuilder.FilterQuery(Mgr.Members, aCompositePredicateDescription);

            Mgr.ExecuteQueryAsync(query, op => op.Results.ForEach(Members.Add));

Back to Top
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 Posted: 26-Oct-2010 at 3:31pm
I finally figured it out. That was hard, like pulling teeth.

          IEntityQuery query = (IEntityQuery)PredicateBuilder.FilterQuery(Mgr.Members, aCompositePredicateDescription);

             Mgr.ExecuteQueryAsync<Member>((IEntityQuery<Member>)query,
                 (op) => {
                     var results = op.Results;
                     results.ForEach(Members.Add);
                 }
                 );

            return Members;
           
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down