Click here to Skip to main content
14,643,391 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm implementing core 3.1 project. In my controller I have a linq query like the following and without defining inprocessapicount and pendingcount which claculates counts of related amounts, it works fine but after adding them to applicants query in select part, applicants returns null and the error is: .Count(a => a.requestStatus == "bb") 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync() . I appreciate if anyone suggests me a solution.

What I want is: There are some applicants in Database and each applicant may have multiple or zero requests. (Each applicant orders multiple or zero itemID) each one of those applicants needs to get some item (itemID) and each of those item has requeststatus =="aa" or requeststatus =="bb" or none of them which the status in that case is "general". Now I want to understand, how many each applicant's itemID has requeststatus=="aa" and how many each applicant's itemID has requeststatus=="bb" according to all ItemId they have ordered.

What I have tried:

var applicants = (from t1 in _context.VwDesk


                                  itemID = t1.ItemId,
                                  applicantID = t1.ApplicantId,
                                  applicantName = t1.ApplicantName,

                                  gateName =t1.GateName,

                                  requestStatus = t1.LastReqStatus
                              group tg by new { tg.requestStatus,tg.itemID ,tg.applicantID, tg.applicantName} into ApiAppGp
                              select new
                                  applicantName = ApiAppGp.Key.applicantName,

                                  itemname = ApiAppGp.Key.itemID,

                                  itemcount =ApiAppGp.Count(),

                                  inprocessapicount = ApiAppGp.Where(a => a.requestStatus == "bb").Count(),
                                  pendingapicount = ApiAppGp.Where(a => a.requestStatus == "aa").Count()

Updated 27-Jul-20 22:36pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This is exactly the same question as Aggregation count returns null in linq core - .NET (Core and Framework) Discussion Boards[^]. Did you create this new account just to post this again? If so please delete both question and the duplicate account.
MinaMr 28-Jul-20 5:17am
No I did make another account because I don't have access to my ordinary system that I used to log in via that and I forgot my password and even I requested to get new password but I didn't receive anything.
Richard MacCutchan 28-Jul-20 5:27am
OK, well post a message to the administrators at Bugs and Suggestions[^], and they will help you. But either way it is considered rude to repost the same question.
0x01AA 10-Aug-20 12:01pm
I hate 1 votes without comments, have a 5.
Richard MacCutchan 10-Aug-20 12:42pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100