传递给viewmodel时出现转换错误

时间:2018-09-04 15:34:06

标签: c# linq asp.net-mvc-5

尝试将IQueryble结果传递给ViewModel时出现以下错误。

  

严重性代码描述项目文件行抑制状态   错误CS0029无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Collections.Generic.List'ETMS D:\ Projects \ ETMS Workspace \ Repo \ ETMS \ Controllers \ ManageTransportController.cs 75活动

我的代码: 查看模型

public class AllTransportGroupResult
{
    public string RootHeading { get; set; }
    public int HeadCount { get; set; }
}

public class OTTransportManagementFormViewModel
{
    public DateTime TransportDateTime { get; set; }

    public List<AllTransportGroupResult> AllTransportGroupResultList { get; set; }
}

我的查询

var query = (from BulkTransportRequestEmployees in _context.BulkTransportRequestEmployees
                     join BulkTransportRequests in _context.BulkTransportRequests on new { BulkRequestBulkRequestId = BulkTransportRequestEmployees.BulkRequestBulkRequestId } equals new { BulkRequestBulkRequestId = BulkTransportRequests.BulkRequestId }
                     join Roots in _context.Roots on new { RootRootId = BulkTransportRequestEmployees.RootRootId } equals new { RootRootId = Roots.RootId }
                     where BulkTransportRequests.TripDateAndTime == vm.TransportDateTime
                     group Roots by new
                     {
                         Roots.RootId,
                         Roots.RootHeading
                     } into g
                     select new 
                     {
                         RootHeading = g.Key.RootHeading,
                         HeadCount = g.Count(p => p.RootId != 0)
                     }).ToList();

绑定到ViewModel:

var viewModel = new OTTransportManagementFormViewModel()
        {
            TransportDateTime = vm.TransportDateTime,
            AllTransportGroupResultList = query
        };

我将查询结果转换为List,但无法正常工作。 请帮助我。

0 个答案:

没有答案