Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Linq GroupBy and Sum - .First() could not be translated

$
0
0

My data is owner, location, date, charge, payment, the plan is to get a list of owners, each having a location, and the Sum OwnerTotal (charge - payamount)

OwnerIdLocationChargePayAmount
1Loc 11000
1Loc 16050
1Loc 1800
2Loc 21000
2Loc 2800
1Loc 1190
2Loc 2180

[Route("ByProviderBilled")]
[HttpGet]
        public async Task<ActionResult<List<TxnsByProvider>>> GetByProviderBilled(int id, bool isbilled) => await context.Transactions
            .Where(p => p.ProviderId == id && p.IsBilled == isbilled).GroupBy(x => x.OwnerBillToId)
            .Select(txn => new TxnsByProvider
            {
                ownerBillToId = (int)txn.First().OwnerBillToId,
                Location = txn.First().OwnerLocation.Location,
                OName = txn.First().OwnerBillTo.Oname,
                OwnerTotal = (decimal)txn.Sum(o => o.Charge - o.PayAmount)
            })
            .OrderByDescending(t => t.OName)
            .ToListAsync();

.Select(s => s.OwnerBillToId)
          .First()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync

Really don't want to take Transactions into memory as is suggested, so maybe there is a different approach I can take without First()?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>