2014-01-15 3 views
4

당신이 도와 주시겠습니까, 부하 운전 예를 들어WCF Ria Service를 사용하여로드하는 일반적인 방법은 무엇입니까? 가능한 경우

에 대한 일반적인 방법이 할 수있는 방법이 있습니다 : 이 부서 데이터를 얻을 그리드에 바인딩하는 일반적인 방법은

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); 
} 

내 질문에 이런 것이있을 수 있습니까? 아래와 같이 일치하는 쿼리에 대한 부하 운전의 기본을 하나의 방법으로 상황에 맞는 쿼리를 반복하고, 예를 들어 쿼리의 이름과 비교 한 후 실행하는 방법이 있는지

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); 
    } 

그래서 궁금했다

당신의 도움은 매우 내가 비슷한 짓을했는지

답변

1

(즉 또는 당신을 아주 미세 조정의 비트와 함께 찾고되지 않을 수도 있습니다 무엇을)

안부, 감사합니다. 내 수업에서 내 뷰 모델에 주입되는 클라이언트 측 데이터 서비스가 무엇인지에 대한 기본 클래스를 만들었습니다.

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); 
    } 

가 그럼 난 DataService에에 전화 :

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"); 

... 또는 뭔가 ...

+0

감사합니다 앨리스가 처음 시작 대답이 질문이 될 수를, 내가 가진 비슷한 기본 클래스,하지만 내가 뭘 찾고 있었는지, 내가 QueryName을 문자열로 전송하여 'Load (context, "QueryName"), 어쨌든 다시 감사합니다. 일반 아이디어로 무엇을 찾고 있었습니까? – keeper

+0

아이디어로 대답이 업데이트되었습니다 ... – Alyce