2012-03-21 1 views
0

RIA 서비스를 사용하는 원격 데이터베이스에서 dtaa를 표시하는 간단한 Silverlight 웹 페이지가 있습니다. 나는 DomainContext을 통해 데이터베이스를 통해 쿼리를 작성합니다.RIA 서비스를 사용하는 DomainContext에 대한 일괄 처리 쿼리

context.Load(context.GetSitesQuery()).Completed += new EventHandler(Query_Completed); 

끝내기 쿼리를 듣고 있습니다. 여기서 문제는 적어도 20 개의 서로 다른 쿼리를 작성해야하며 각 쿼리는 서로 다른 개체 개체를 포함해야합니다. 응용 프로그램은 모든 데이터가로드 될 때까지는 많은 것을 할 수 없습니다. 그래서, 나는 모든 쿼리가 끝난 시점을 알고 싶을뿐입니다. 검색어 묶음을 쉽게 만들 수 있습니까?

나는 이것을 독자적으로 시도했지만 각 쿼리가 다른 엔티티와 관련되어 있기 때문에 문제가 발생했습니다. 내가 EntityQuery<Entity>의 목록을 작성하고 그것을 반복하고 모든 쿼리를 실행할 수 있다고 생각했지만 Load 메소드는 잘못된 매개 변수가있는 것에 대해 불만을 나타내거나 런타임 중에 실패합니다.

답변

0

우리는 보류중인로드 조작의 수를 추적하여 수행하려는 작업을 완료했습니다. 0에 도달하면 효과적입니다.

using System.ServiceModel.DomainServices.Client; 

... 

private int _loadCounter; 
private TheDomainContext _domainContext; 

private void Load<TEntity>(EntityQuery<TEntity> query, 
          Action<LoadOperation<TEntity>> callback) 
         where TEntity : Entity 
{ 
    BeginLoading(); 
    Action<LoadOperation<TEntity>> internalCallback = 
      loadOp => { 
          callback(loadOP); 
          EndLoading(); 
         }; 
    _domainContext.Load(query, internalCallback , null); 
} 

private void BeginLoading() 
{ 
    _loadCounter++; 
    // You could add logic to indicate the app is busy 
} 

private void EndLoading() 
{ 
    _loadCounter--; 
    if (_loadCounter == 0) 
    { 
     OnLoadComplete(); 
    } 
} 

private void OnLoadComplete() 
{ 
    // TODO Everything is loaded 
} 

private void BeginLoadingTheQueries() 
{ 
    // Increment once here to prevent the OnLoadComplete from occurring 
    // before all queries have started 
    BeginLoading(); 
    Load(_domainContext.GetSitesQuery(), Query_Completed); 
    Load(_domainContext.GetOtherQuery(), OtherQuery_Completed); 
    EndLoading(); 
} 
+0

어떻게 'TEntity'에 대한 참조를 얻습니까? (C# 태그를 추가해 주셔서 감사합니다) –

+0

'where TEntity : Entity'와 필요한'using' 문을 추가했습니다. –

+0

감사합니다. 이것은 기본적으로 내가 이미 가지고있는 것입니다. 나는 그것을하기위한 더 좋은 방법이 있었으면 좋겠지 만, 이것이 괜찮은 것 같아요. –