将 LINQ 结果存储到引用多个 class 对象的视图模型中,而不是将 LINQ 结果存储在 var 中

Store LINQ result into view-model refereeing to multiple class objects instead of storing LINQ result in var

我的 linq 语句给出了三个 class 对象数据

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;
    }

更改视图模型

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();

我没有测试代码,只是建议你一个方法,寻找更好的解决方案。