【发布时间】:2024-04-29 20:55:02
【问题描述】:
我有给出三个类对象数据的 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;
}
【问题讨论】:
-
您的查询返回 1 个包含 3 个对象的列表。而不是返回包含 3 个列表的 1 个对象。因此,您应该对数据进行分组。
标签: c# entity-framework linq viewmodel