我已经用谷歌搜索了这个错误并在这里阅读了一些关于堆栈溢出的帖子,但我仍然不明白这里的问题是什么。我理解“英语”,但不理解程序化推理。为什么我可以这样做:
public void FillRegister(ItemMovementRegister register, IDateRange imqp)
{
var f = from detail in this.Context.ItemMovements
where (detail.MovementDate >= imqp.StartDate) &&
(detail.MovementDate <= imqp.EndDate)
orderby detail.MovementDate descending
select new ItemMovement(detail.SourceSystemId,
(ItemMovementKind)detail.MovementKind,
detail.MovementDate.DateTime,
detail.UniversalMovementKey,
detail.UniversalMaterialItemKey,
((detail.SourceDocumentRef != null) ? detail.SourceDocumentRef.Trim() : string.Empty),
((detail.SourceComment != null) ? detail.SourceComment.Trim().Replace("Sale: ", "").Substring(0, 20) : string.Empty),
detail.ActualDeltaQty)
{
MovementKindName = detail.MovementKindName.Trim()
};
register.AddRange(f.ToList<ItemMovement>());
}
但不是这个:
public void FillRegister(ItemMovementRegister register, IDateRange imqp)
{
try
{
var f = from detail in this.Context.ShippingDocumentDetails
join header in this.Context.ShippingDocuments on detail.ClientOrderNumber equals header.ClientOrderNumber
where (header.DateOrdered >= imqp.StartDate)
&& (header.DateOrdered <= imqp.EndDate)
orderby header.DateOrdered descending
select new ItemMovement(long.Parse(ConfigurationManager.AppSettings["PickedOrderSourceSystem"]),
ItemMovementKind.Picked,
((header.DateOrdered.HasValue) ? header.DateOrdered.Value : new DateTime(1900, 1, 1)),
UniversalItemMovementConverter.GetMovementKeyFromShippingDocument(header.ClientOrderNumber),
detail.ProductCode,
header.ClientOrderNumber,
string.Empty,
((detail.QuantityDelivered.HasValue) ? detail.QuantityDelivered.Value : 0)) { };
List<ItemMovement> ms = f.ToList<ItemMovement>(); // Fails here
this.UpdateItemMovements(ms);
register.AddRange(ms);
}
catch (Exception ex)
{
throw new DALException("void FillItemMovements(ItemMovementRegister register, IDateRange imqp) failed :" + ex.Message, ex);
}
}