linq クエリが機能しないのはなぜですか?
遅延読み込みと関係があるのではないかと思います。linqpadで動作するようです。
public IList<PaymentDto> GetDocumentPayments(int documentId, bool? allowRepeatPayments, byte[] paymentStatuses, int[] paymentMethods)
{
using (var ctx = ObjectContextManager<MyDataContext>.GetManager("MyDataContext"))
{
var payments = new List<PaymentDto>();
var ps = new List<byte>();
if (paymentStatuses != null)
{
ps = paymentStatuses.ToList();
}
var pm = new List<int>();
if (paymentMethods != null)
{
pm = paymentMethods.ToList();
}
IQueryable<Payment> data =
from payment in ctx.ObjectContext.Documents.OfType<Payment>()
where
ps.Contains(payment.Status) &&
pm.Contains(payment.Method) &&
payment.DocumentId == documentId &&
(allowRepeatPayments == null || payment.AllowRepeatPayments == allowRepeatPayments)
orderby payment.Id
select payment;
foreach (var p in data) // Fails here
{
payments.Add(ReadData(p));
}
return payments;
}
}
スローされるエラー: CollectionType が必要です。パラメータ名: collectionType.