【发布时间】:2021-04-26 21:45:37
【问题描述】:
在我的数据库中,我有一个连接表来存储 JobType 和 DocumentType 之间的多对多关系(简化描述)
工作类型表
| Column | Type |
|---|---|
| Id | int |
| Description | varchar(100) |
文档类型表
| Column | Type |
|---|---|
| Id | int |
| Description | varchar(100) |
具有以下列的 JobTypeDocumentType:
| Column | Type |
|---|---|
| Id | int |
| JobType | int |
| DocumentType | int |
我想从数据库中检索数据并将结果记录集转换为IObservable<collection<ViewModels>>。
在下面的代码中,GetJobDocumentTypes 方法返回 JobTypeDocumentType POCO 的集合:
IObservable<IReadOnlyCollection<JobTypeDocumentType>> dataService.GetJobDocumentTypes(int jobTypeId)`
The purpose of getJobTypeDocumenTypeViewModels is to transform the returned POCOs into ViewModels:
private IObservable<IEnumerable<JobTypeDocumentTypeViewModel>> getJobTypeDocumenTypeViewModels(JobType jobType)
{
var result = dataService.GetJobDocumentTypes(jobType.Id)
.Select(items => items.Select(jtdt =>
dataService.GetById<DocumentType>(jtdt.DocumentType_Id)
.Select(dt => new JobTypeDocumentTypeViewModel(jtdt, jobType, dt))));
return result;
}
但是,我被 IObservable<IEnumerable<IObservable<JobTypeDocumentTypeViewModel>>> 类型的结果卡住了
任何帮助和/或建议将不胜感激。
【问题讨论】: