0

ピープス、

私は Silverlight の生まれ変わった処女なので、ご容赦ください。2 つの異なる SQL データベース サーバーを指す 2 つの個別の DomainServices があります。これらのドメイン サービス内で、各ドメイン サービスにいくつかの IQueryables をセットアップしました。

別の DomainServices から 2 つの IQueryables をマージする必要があります。これは実行可能でなければならないと確信しています。

以下は、2 つのドメイン サービスです。

GetCustomCallLogs (HEATLiveDomainService から) と GetTblCallsLogged (HeatDomainService から) をマージしたいと考えています。GetCustomCallLogs のキーは CallID になり、GetTblCallsLogged のキーは RecID になります。

可能であれば、結合された2つのテーブルのフィールドを考慮して新しいタイプを作成する必要があることを理解しています。

うまくいけば、私は私のシナリオを説明し、私は愚かではありません.

前もって感謝します

  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 Server) で行うことは問題外です。SPを作成してOpenQueryを使用することはできません(できますが、正しく行う方法を学びたいです)。これは正しい方法ではないと確信しています。

4

1 に答える 1

0

各サービスから返される 2 つの異なる型をラップするために 3 番目の型が必要になる場合がありますが、これは使用方法によって異なります。

ItemsControl は、コレクション内の型 (リストボックス、コンボボックスなど) を気にしませんが、GridView 型のコントロールはうるさい場合があります。

linq を使用すると、両方のリストを簡単にマージできます。次のようなものがうまくいくはずです:

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

Select and Cast は、クエリによって適切なジェネリック コレクションが作成されるようにするためのものです。

これを調整して、ラッパー タイプへの変換も組み込むことができます。つまり、Object にキャストする代わりに、ラッパー クラスの新しいインスタンスを返すだけです。

必要に応じて Union を使用することもできます。

すべてを一緒に入れて:

collection1.Select(o => new MyWrapperType(o))
    .Union(collection2.Select(o => new MyWrapperType(o)));
于 2013-02-03T09:46:36.277 に答える