views:

73

answers:

1

Given a function as below, i can take a single table from my database and write a lambda using the Where extension method and pretty much build all the other cases using a simple wrapper method and supplying a filter.

  public void getPeople(Expression<Func<tblPeople, bool>> filter, Action<List<tblPeople>> callback)
            {
                var query = from People in sdContext.tblPeople.Where(filter)
                            select People;


                var DSQuery = (DataServiceQuery<tblPeople>)query;
                DSQuery.BeginExecute(result =>
                {
                    callback(DSQuery.EndExecute(result).ToList<tblPeople>());

                }, null);
            }

What I really would like to do now is write an even more generic method, that abstracts out the tblPeople to a parameter. This way I could just have one line methods for all my calls, at least those that provide lists! How can I take this and build:

 public void getTable<T>(Expression<Func<T, bool>> filter, Action<List<T>> callback)
            {
                var query = from DB in sdContext.T.Where(filter)
                            select DB;


                var DSQuery = (DataServiceQuery<T>)query;
                DSQuery.BeginExecute(result =>
                {
                    callback(DSQuery.EndExecute(result).ToList<T>());

                }, null);
            }

Is this possible!

A: 

This might work...

public void getTable<T>(Expression<Func<T, bool>> filter, Action<List<T>> callback)
{
    var query = from DB in sdContext.GetTable<T>.Where(filter)
                select DB;


    var DSQuery = (DataServiceQuery<T>)query;
    DSQuery.BeginExecute(result =>
    {
        callback(DSQuery.EndExecute(result).ToList<T>());
    }, null);
}
Jason Punyon
I should have specified that I am using ADO.NET Dataservices and I don't think this GetTable method is available in the silverlight client library. It is almost what I was looking for!
DavidA