Peeps,
我是银光重生的处女,所以请耐心等待。 我有两个单独的域服务,指向两个不同的 SQL 数据库服务器。 在这些域服务中,我在每个域服务中设置了一些IQueryable。
我需要将两个来自单独域服务的 IQueryable 合并在一起。 我确信这必须是可行的。
以下是两个域服务。
我想将 GetCustomCallLogs(来自 HEATLiveDomainService)与 GetTblCallsLoged(来自 HeatDomainService)合并。 GetCustomCallLogs 中的键是 CallID,GetTblCallsLogging 中的键是 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(好吧,我可以,但我想学习正确执行此操作),因为我确定这不是正确的方法。
您可能需要第三种类型来包装从每个服务返回的两种不同类型,但这取决于您希望如何使用它。
ItemsControl 不会关心集合中的类型(列表框、组合框等),但 GridView 类型控件可能会很挑剔。
使用 linq,可以简单地合并两个列表。像下面这样的东西应该可以解决问题:
collection1.Select(o => (object)o).Concat(collection2.Select(o => (object)o));
选择和强制转换是为了由查询创建适当的泛型集合。
这也可以进行调整以将转换合并到您的包装器类型中。 即不要强制转换为对象,只需返回包装器类的新实例即可。
如果合适,您甚至可以使用联合。
把所有的东西放在一起:
collection1.Select(o => new MyWrapperType(o))
.Union(collection2.Select(o => new MyWrapperType(o)));