Linq Group Not accepting an internal entity

I use an entity structure and make a group by table. My request is as follows: -

var brokerPaymentLists = dbContext.BrokerPayments .Include("PaymentDetail") .Where(bp => bp.IdPaymentStatus == (long)EntityModel.Additions.Variables.PaymentStatus.ALLOTED) .GroupBy(bp => bp.IdBroker, (key, g) => new { IdBroker = key.Value, BrokerPayments = g.ToList() }).ToList(); 

I have enabled PaymentDetail, but after grouping, I can see that the paymentdetail for each item in BrokerPayments is null. Any suggestion why this is the case, as well as how I can make the group so that I can complete my payment verification each of BrokerPayments;

+6
source share
1 answer

Looking forward to using Include requires that the data form does not change since Include is applied. In your case, this means the query should return an IQueryable<BrokerPayments> . But the GroupBy operator changes shape because it returns IQueryable<IGrouping<TKey, TSource>> . The same thing will happen with projections and user associations.

As a workaround, you can group in LINQ with objects such as:

 var brokerPaymentLists = dbContext.BrokerPayments .Include("PaymentDetail") .Where(bp => bp.IdPaymentStatus == (long)EntityModel.Additions.Variables.PaymentStatus.ALLOTED) .AsEnumerable() .GroupBy(bp => bp.IdBroker, (key, g) => new { IdBroker = key.Value, BrokerPayments = g }); 

NOTE. Please note that exectuion request will not be a deferder

+1
source

All Articles