BeginRefresh With Criteria

BeginRefresh With Criteria

Old forum URL: forums.lhotka.net/forums/t/11574.aspx


mehgerbil posted on Tuesday, September 11, 2012

I've the following code that works fine:

BeginRefresh(Library.Records.TaskList.GetTaskList);

This code is located the viewmodel and it works really well.  My problem is that I don't know how to alter it to handle a criteria object (or parameters).  Is there a way to create a criteria object and pass it into this mess?   I apologize for the noob question - I'm still learning all this lambda stuff.  Obviously, I'm using BXF here.

kgulden replied on Tuesday, September 11, 2012

You can create a criteria object as an encapsulated class within TaskList.

Something like:

  public class TaskList....
  {
    public class CriteriaForTaskByName : CriteriaBase<CriteriaForTaskByName>
    {
      public static readonly PropertyInfo<string> PhraseProperty =
        RegisterProperty<string>(c => c.Name);
       public string Name
       {
         get { return ReadProperty(NameProperty); }
         set { LoadProperty(NameProperty, value); }
       }
    }

   ... other stuff....
  }

  // Add a GetTaskList using the criteria:

  public static void GetTaskList(CriteriaForTaskByName criteria,
    EventHandler<DataPortalResult<TaskList>> callback)
  {
    DataPortal.BeginFetch<TaskList>(criteria, callback);
  }

  // In Data Access region

  private void DataPortal_Fetch(CriteriaForTaskByName criteria)
  {
  }

}

In your ViewModel use:

    public FetchWithCriteria(string name)
    {
      TaskList.CriteriaForTaskByName =
       new TaskList.CriteriaForTaskByName() { Name = name };

      BeginRefresh( Library.Records.TaskList.GetTaskList(criteria) );
    }

 

 

mehgerbil replied on Wednesday, September 12, 2012

I get an error in the viewmodel on this line:

BeginRefresh( Library.Records.TaskList.GetTaskList(criteria) );

The error says: No overload method GetTaskList takes one argument. I think that is because GetTaskList, as you have it above, takes a criteria and a callback and I'm only passing in the criteria.

 

mehgerbil replied on Wednesday, September 12, 2012

Okay, I found the answer.   I replaced the problem line with this code:

BeginRefresh(callback => Library.Records.TaskList.GetTaskList(criteria, callback));

 

 

kgulden replied on Wednesday, September 12, 2012

Yeah, you got it.  Sorry about that mistake.

Copyright (c) Marimer LLC