私はこのエラーをグーグルで検索し、ここでスタックオーバーフローに関するいくつかの投稿を読みましたが、ここで何が問題なのかまだわかりません。私は「英語」を理解していますが、プログラム的な推論は理解していません。なぜ私はこれを行うことができます:
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);
}
}