实体或复杂类型' MedPModel.Customer'无法在LINQ to Entities查询中构造

时间:2017-12-20 13:34:41

标签: c# entity-framework linq linq-to-entities

当我将wms_SOHeaderResults转换为列表时,我收到了主题中提到的错误。有关如何解决它的任何想法?

 var wms_SOHeaderResults = from soh in _mpiContext.SalesOrders.AsNoTracking()
        join cu in _mpiContext.Customers.AsNoTracking() on soh.CustomerId equals cu.CustomerId into group_soh_cu
        join cs in _mpiContext.CarrierServices on soh.CarrierServiceId equals cs.ServiceId into group_soh_cs
        orderby soh.OrderedOnDate descending
        from cu in group_soh_cu.DefaultIfEmpty(new Customer() { CustomerId = soh.CustomerId, CustomerName = default(string) })
        from cs in group_soh_cs.DefaultIfEmpty(new Data.CarrierService() { ServiceId = soh.CarrierServiceId ?? default(Guid), ServiceName = default(string) })
        where soh.OrderedOnDate > so_CutOff
        select new WMS_SOHeaderVM
        {
            SalesOrderId = soh.SalesOrderId,
            SalesOrderNumber = soh.SalesOrderNumber,
            OrderedOnDate = soh.OrderedOnDate,
            PromisedByDate = soh.PromisedByDate,
            PickOnDate = soh.PickOnDate,
            LateAfterDate = soh.LateAfterDate,
            CarrierServiceId = soh.CarrierServiceId,
            CarrierServiceName = cs.ServiceName,
            CustomerPo = soh.CustomerPO,
            CustomerId = soh.CustomerId,
            CustomerName = cu.CustomerName,
            FieldSalesForceId = soh.FieldSalesForceId,
            RevisionNumber = soh.RevisionNumber,
            SalesForceId = soh.SalesForceId,
            LockId = soh.LockId,
            SalesOrderStatus = soh.SalesOrderStatus,
            SalesOrderStatusComputed = soh.SalesOrderStatusComputed,
            SalesOrderType = soh.SalesOrderType,
            SalesOrderTypeComputed = soh.SalesOrderTypeComputed
        };

var x = wms_SOHeaderResults.ToList();

0 个答案:

没有答案