我有linq语句,它提供了三个类对象数据
1- appForm 2- ebsSync 3- SyncAuditLog
var _AppForms2 = (from appForm in _uof.Web_AppFormsRepository.GetAll()
join syncAuditLog in (_uof.Web_SyncAuditLogRepository.GetAll().
Where(sal => sal.LOG_STATUS.Equals("EP") &&
sal.LOOKUP_ID != null &&
sal.ID == maxAuditID)
.Select(shortListedAuditLog => new { shortListedAuditLog })) on appForm.SUBMISSION_ID equals syncAuditLog.shortListedAuditLog.SUBMISSION_ID
join ebsSync in _uof.Web_EBS_SyncRepository.GetAll() on appForm.SUBMISSION_ID equals ebsSync.SUBMISSION_ID
select new {appForm , ebsSync, syncAuditLog }).ToList();
我想将此LINQ查询结果存储到viewModel中,而不是'var _AppForms';
public class WebSyncSummaryEntity
{
public List<Web_AppFormsEntity> AppFormsEntity { get; set; }
public List<Web_EBS_SyncEntity> EBS_SyncEntity { get; set; }
public List<Web_SyncAuditLogEntity> SyncAuditLogEntity { get; set; }
}
public List<WebSyncSummaryEntity> GetWebSyncSummary()
{
List<WebSyncSummaryEntity> _AppForms = null;
using (var _uof = new UCAS_WebSync_AdminTool_UOF())
{
var maxAuditID = (from sal in _uof.Web_SyncAuditLogRepository.GetAll().Where(
sal => sal.LOG_STATUS.Equals("EP") &&
sal.LOOKUP_ID != null)
select sal).Max(x => x.ID);
_AppForms = (from appForm in _uof.Web_AppFormsRepository.GetAll()
join syncAuditLog in (_uof.Web_SyncAuditLogRepository.GetAll().
Where(sal => sal.LOG_STATUS.Equals("EP") &&
sal.LOOKUP_ID != null &&
sal.ID == maxAuditID)
.Select(shortListedAuditLog => new { shortListedAuditLog })) on appForm.SUBMISSION_ID equals syncAuditLog.shortListedAuditLog.SUBMISSION_ID
join ebsSync in _uof.Web_EBS_SyncRepository.GetAll() on appForm.SUBMISSION_ID equals ebsSync.SUBMISSION_ID
select new {appForm , ebsSync, syncAuditLog }).ToList();
var test = "d";
}
return _AppForms;
}
答案 0 :(得分:1)
更改您的视图模型
public class WebSyncSummaryEntity
{
public Web_AppFormsEntity AppFormsEntity { get; set; }
public Web_EBS_SyncEntity EBS_SyncEntity { get; set; }
public Web_SyncAuditLogEntity SyncAuditLogEntity { get; set; }
}
然后
var _AppForms2 = (from appForm in _uof.Web_AppFormsRepository.GetAll()
join syncAuditLog in (_uof.Web_SyncAuditLogRepository.GetAll().
Where(sal => sal.LOG_STATUS.Equals("EP") &&
sal.LOOKUP_ID != null &&
sal.ID == maxAuditID)
.Select(shortListedAuditLog => new { shortListedAuditLog })) on appForm.SUBMISSION_ID equals syncAuditLog.shortListedAuditLog.SUBMISSION_ID
join ebsSync in _uof.Web_EBS_SyncRepository.GetAll() on appForm.SUBMISSION_ID equals ebsSync.SUBMISSION_ID
select new WebSyncSummaryEntity {AppFormsEntity =appForm , EBS_SyncEntity =ebsSync, SyncAuditLogEntity =syncAuditLog }).ToList();
我还没有对代码进行过测试,只是建议您选择一种方法,寻找更好的解决方案。