偷看,
我是 Silverlight 的重生处女,所以请多多包涵。我有两个单独的 DomainServices,指向两个不同的 SQL 数据库服务器。在这些域服务中,我在每个域服务中设置了一些 IQueryable。
我需要将两个 IQueryables 从单独的 DomainServices 合并在一起。我确信这必须是可行的。
下面是两个域服务。
我想将 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 Server)上这样做是不可能的。无法创建 SP 并使用 OpenQuery(我可以,但我想学会正确地做到这一点),因为我确信这不是正确的做法。