Common way to boot using WCF Ria service?

Could you help, if possible, there is a way to have a common way to work with the load.

For example: This is a normal way to get department data and snap it to a grid.

grid.ItemsSource = context.Departments;
LoadDepartmentsData();

private void LoadDepartmentsData()
{
 EntityQuery<Department> query = context.GetDepartmentsQuery();
 context.Load(query, LoadOperationIsCompleted, null);
}

private void LoadOperationIsCompleted(LoadOperation<Department> obj) 
{
            if (obj.HasError)
                MessageBox.Show(obj.Error.Message);
}

So my question is: is something like this possible?

    grid.ItemsSource = context.Departments;

    grid.ItemsSource = context.Departments;
    LoadData("GetDepartmentsQuery");

    private void LoadData(string queryName)
    {
     …..?
    }

    private void LoadOperationIsCompleted(LoadOperation obj) 
    {
                if (obj.HasError)
                    MessageBox.Show(obj.Error.Message);
    }

So, I was wondering if there is a way to iterate through contextual queries in one method and compare it with the name of the query, for example, and then execute the database of load operations on a consistent request, as shown below.

Your help is much appreciated

Regards,

+4
source share
1 answer

- ( , ). , , . - ( ):

protected readonly IDictionary<Type, LoadOperation> pendingLoads = 
    new Dictionary<Type, LoadOperation>();

protected void Load<T>(EntityQuery<T> query, 
    LoadBehavior loadBehavior, 
    Action<LoadOperation<T>> callback, object state) where T : Entity
    {
        if (this.pendingLoads.ContainsKey(typeof(T)))
        {
            this.pendingLoads[typeof(T)].Cancel();
            this.pendingLoads.Remove(typeof(T));
        }

        this.pendingLoads[typeof(T)] = this.Context.Load(query, loadBehavior, 
            lo =>
        {
            this.pendingLoads.Remove(typeof(T));
            callback(lo);
        }, state);
    }

:

Load<Request>(Context.GetRequestQuery(id), loaded =>
        {
             // Callback
        }, null);

: , Ria Services (- , ). , , , Load , , , . ( , , ):

// In the base class
protected void Load(string queryName)
{
    // Get the type of the domain context
    Type contextType = Context.GetType();
    // Get the method information using the method info class
    MethodInfo query = contextType.GetMethod(methodName);

    // Invoke the Load method, passing the query we got through reflection
    Load(query.Invoke(this, null));
}

// Then to call it
dataService.Load("GetUsersQuery");

... -...

+1

All Articles