2013-02-01 5 views
0

들여다보기,여러 IQueryables를 함께 병합 - Silverlight

Im 다시 태어난 실버 버스트이므로 나와 함께하시기 바랍니다. 두 개의 서로 다른 SQL 데이터베이스 서버를 가리키는 두 개의 별도 DomainServices가 있습니다. 이러한 도메인 서비스 내에서 각 도메인 서비스에 IQueryables를 설치했습니다.

별도의 DomainServices에서 두 개의 IQueryables를 병합해야합니다. 이게 할 수 있어야한다고 확신 해요.

다음은 두 도메인 서비스입니다.

GetCustomCallLogs (HEATLiveDomainService)와 GetTblCallsLogged (HeatDomainService)를 병합하고 싶습니다. GetCustomCallLogs의 키는 CallID이고 GetTblCallsLogged의 키는 RecID입니다.

가능한 경우 계정에 두 개의 조인 된 테이블의 모든 필드를 가져올 새 형식을 만들어야한다는 것을 이해해야합니다.

내 시나리오에 대해 설명해 주셨으면합니다. 사전에

감사

public class HEATLIVEDomainService : LinqToEntitiesDomainService<HeatIT9_LiveEntities> 
{ 

    // TODO: 
    // Consider constraining the results of your query method. If you need additional input you can 
    // add parameters to this method or create additional query methods with different names. 
    // To support paging you will need to add ordering to the 'Assignees' query. 
    public IQueryable<Assignee> GetAssignees() 
    { 
     return this.ObjectContext.Assignees; 
    } 

    // TODO: 
    // Consider constraining the results of your query method. If you need additional input you can 
    // add parameters to this method or create additional query methods with different names. 
    // To support paging you will need to add ordering to the 'CallLogs' query. 
    public IQueryable<CallLog> GetCallLogs() 
    { 
     //   return this.ObjectContext.CallLogs.Where(c => DateTime.Parse(c.ClosedDate).Year == 2012 && c.CallStatus == "Closed" && c.ClosedBy.Length > 0); 
     return this.ObjectContext.CallLogs.Where(c => c.CallStatus == "Closed" && c.ClosedDate.Substring(0, 4).Equals("2013")); 
    } 

    public IQueryable<CallLog> GetCallLogsLastThisYear() 
    { 
     return this.ObjectContext.CallLogs.Where(c => c.CallStatus == "Closed" && (c.ClosedDate.Substring(0, 4).Equals("2012") || c.ClosedDate.Substring(0, 4).Equals("2013"))); 
    } 

    public IQueryable<CustomCallLog> GetCustomCallLogs(string year) 
    { 
     var result = from i in this.ObjectContext.CallLogs 
     join p in this.ObjectContext.Assignees on i.ClosedBy equals p.LoginID 
     where i.CallStatus == "Closed" && i.ClosedDate.Substring(0, 4) == year 
     select new CustomCallLog 
     { 
      Score = 
      CallLog = i.CallID, 
      Name = p.Assignee1, 
      Yr = year, 
      Mth = i.ClosedDate.Substring(5, 2), 
      GroupName = p.GroupName 
     }; 
     return result; 
    } 


    public IQueryable<CustomClosedJobs> GetCustomClosedJobs() 
    { 
     var result = from i in this.ObjectContext.CallLogs 
        where i.CallStatus == "Closed" && i.ClosedDate.Substring(0, 4) =="2012" 
        group i by i.ClosedDate.Substring(5,2) into y 
        select new CustomClosedJobs 
        { 
         Type = "heat", 
         ClosedCalls = y.Count(), 
          Mth =y.Key 
        }; 
     return result; 
    } 


    // TODO: 
    // Consider constraining the results of your query method. If you need additional input you can 
    // add parameters to this method or create additional query methods with different names. 
    // To support paging you will need to add ordering to the 'Subsets' query. 
    public IQueryable<Subset> GetSubsets() 
    { 
     return this.ObjectContext.Subsets; 
    } 
} 

public class HEATDomainService : LinqToEntitiesDomainService<FEEDBACKPRDEntities1> 
{ 

    // TODO: 
    // Consider constraining the results of your query method. If you need additional input you can 
    // add parameters to this method or create additional query methods with different names. 
    // To support paging you will need to add ordering to the 'qryStoringLogs' query. 
    public IQueryable<qryStoringLog> GetQryStoringLogs() 
    { 
     return this.ObjectContext.qryStoringLogs.OrderBy(e => e.monthno); 
    } 

    public IQueryable<tblStoringLog> GetTop100Logs() 
    { 
     return this.ObjectContext.tblStoringLogs.OrderByDescending(e => e.responsetime).Take(100); 
    } 

    public IQueryable<tblStoringLog> GetLogCount(DateTime s, DateTime e) 
    { 
     return this.ObjectContext.tblStoringLogs.Where(x => x.responsetime >= s && x.responsetime <= e); 
    } 

    public IQueryable<qryStoringLog> GetLogs(int year, int mth) 
    { 
     return this.ObjectContext.qryStoringLogs.Where(e => e.Month.Equals(mth) && e.yr.Equals(year)); 
    } 

    public IQueryable<qryStoringLog> GetLogsForYear(int year) 
    { 
     return this.ObjectContext.qryStoringLogs.Where(e => e.yr.Equals(year)).OrderBy(e => e.monthno); 
    } 

    public DateTime GetFirstDate() 
    { 
     return (DateTime)this.ObjectContext.tblStoringLogs.OrderBy(e => e.responsetime).First().responsetime; 
    } 

    public DateTime GetLastDate() 
    { 
     return (DateTime)this.ObjectContext.tblStoringLogs.OrderByDescending(e => e.responsetime).First().responsetime; 
    } 

    public IQueryable<tblCallLogged> GetTblCallLoggeds() 
    { 
     return this.ObjectContext.tblCallLoggeds; 
    } 

    public IQueryable<tblStoringLog> GetTblStoringLogs() 
    { 
     return this.ObjectContext.tblStoringLogs; 
    } 

    [Query(IsComposable = false)] 
    public IQueryable<qryStoringLog> GetTblStoringLogsStatus(int statusid) 
    { 
     return this.ObjectContext.qryStoringLogs.Where(e => e.statusid == statusid); 
    } 


    public IQueryable<stResponsesLife_Result> LifeTimeResponses() 
    { 
     return this.ObjectContext.stResponsesLife().AsQueryable(); 
    } 


    public IEnumerable<CustomLifetime> GetCustomLifeTime() 
    { 
     var result = from i in this.ObjectContext.stResponsesLife().ToList() 
        select new CustomLifetime 
        { 
         Dates = i.Dates, 
         Vals = (int)i.Vals 
        }; 
     return result; 
    } 


    public int GetAllResponses() 
    { 
     return this.ObjectContext.qryStoringLogs.Count(); 
    } 

} 

주의 사항 : 가 너무 밖으로 질문 소스 (SQL 서버)에서 그 일을, 서버에 연결 할 수 없습니다. SP를 만들고 OpenQuery를 사용할 수 없습니다. (정확히 할 수는 있지만 올바른 방법을 배우고 싶습니다.) 올바른 방법은 아닙니다.

답변

0

각 서비스에서 반환 된 두 가지 유형을 래핑하려면 세 번째 유형이 필요할 수 있지만 사용 방법에 따라 다릅니다.

ItemsControl은 컬렉션 (Listbox, 콤보 박스 등)에 어떤 유형이 있는지 신경 쓰지 않지만 GridView 유형 컨트롤은 까다 롭습니다.

linq를 사용하면 두 목록을 간단히 병합 할 수 있습니다. 다음과 같은 것이 트릭을 수행해야합니다 :

collection1.Select(o => (object)o).Concat(collection2.Select(o => (object)o)); 

선택 및 전송은 해당 제네릭 컬렉션이 쿼리에 의해 생성되도록하기위한 것입니다.

래퍼 유형으로의 변환도 통합되도록 조정할 수 있습니다. 즉, Object로 캐스팅하는 대신 래퍼 클래스의 새 인스턴스를 반환하면됩니다.

적절한 경우 유니언을 사용할 수도 있습니다.

모두 함께 퍼팅 :

collection1.Select(o => new MyWrapperType(o)) 
    .Union(collection2.Select(o => new MyWrapperType(o)));