Hello Team,
I notice in my controller that, it is not loading multiple data with the same Id, ei when I select term one for two or three student, the controller only load one data out of the rest.
public ActionResult getAllFeesPayment()
{
var dataList = objBasicShoolDBEntities.tblFeesPayments.Join(objBasicShoolDBEntities.tblExams,
fee => fee.FeesId,
exam => exam.ExamsTermId,
(fee, exam) => new { fee = fee, exam = exam }).Join(objBasicShoolDBEntities.tblRegistrationFees,
exam => exam.fee.RegistrationId,
registration => registration.RegistrationId,
(exam, registration) => new { registration = registration, exam = exam });
var modifiedData = dataList.GroupBy(x => new { x.exam.fee.FeesId, x.exam.fee.PaymentDate }).Select(x => new TermlyFeesPaymentViewModel
{
FeesId = x.Key.FeesId,
PaymentDate = x.FirstOrDefault().exam.fee.PaymentDate,
FirstName = x.FirstOrDefault().exam.fee.FirstName,
LastName = x.FirstOrDefault().exam.fee.LastName,
ExamsTermId = x.FirstOrDefault().exam.fee.ExamsTermId,
ExamTerm = x.FirstOrDefault().exam.fee.tblExam.ExamTerm,
RegistrationId = x.FirstOrDefault().exam.fee.RegistrationId,
ClassName = x.FirstOrDefault().exam.fee.tblRegistrationFee.ClassName,
Fees = x.FirstOrDefault().exam.fee.tblRegistrationFee.Fees,
FeesPaid = x.FirstOrDefault().exam.fee.FeesPaid,
Wallet = x.FirstOrDefault().exam.fee.Wallet
}).ToList();
return Json(modifiedData, JsonRequestBehavior.AllowGet);
}



Abhishek ChadhaRank #402 · 6.2K reputationPosted May 10, 2024, 2:25 PM EDT
try the below ---
var modifiedData = dataList.Select(x => new TermlyFeesPaymentViewModel
{
FeesId = x.exam.fee.FeesId,
PaymentDate = x.exam.fee.PaymentDate,
FirstName = x.exam.fee.FirstName,
LastName = x.exam.fee.LastName,
ExamsTermId = x.exam.fee.ExamsTermId,
ExamTerm = x.exam.fee.tblExam.ExamTerm,
RegistrationId = x.exam.fee.RegistrationId,
ClassName = x.exam.fee.tblRegistrationFee.ClassName,
Fees = x.exam.fee.tblRegistrationFee.Fees,
FeesPaid = x.exam.fee.FeesPaid,
Wallet = x.exam.fee.Wallet
}).ToList();
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted May 10, 2024, 2:34 PM EDT
Hello Abhishek Chadha
Please it is still the same, is not working
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 11, 2024, 6:28 AM EDT
Hello,
Try with below code.
var modifiedData = dataList.Select(x => new TermlyFeesPaymentViewModel { FeesId = x.Key.FeesId, PaymentDate = x.FirstOrDefault().exam.fee.PaymentDate, FirstName = x.FirstOrDefault().exam.fee.FirstName, LastName = x.FirstOrDefault().exam.fee.LastName, ExamsTermId = x.FirstOrDefault().exam.fee.ExamsTermId, ExamTerm = x.FirstOrDefault().exam.fee.tblExam.ExamTerm, RegistrationId = x.FirstOrDefault().exam.fee.RegistrationId, ClassName = x.FirstOrDefault().exam.fee.tblRegistrationFee.ClassName, Fees = x.FirstOrDefault().exam.fee.tblRegistrationFee.Fees, FeesPaid = x.FirstOrDefault().exam.fee.FeesPaid, Wallet = x.FirstOrDefault().exam.fee.Wallet }).GroupBy(x => new { x.Key.FeesId, x.FirstOrDefault().exam.fee.PaymentDate }).ToList();Thanks
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted May 11, 2024, 11:06 AM EDT
Hello Jaimin
This is the error that popup and when I took away the FirstOrDefault(), additional error popup saying PaymentDate is not defined.
Jignesh KumarRank #91 · 22.9K reputationPosted May 12, 2024, 3:58 AM EDT
Hello Emmanuel,
Have you been able to check all tables where you have used join have data for the specified condition for your join?
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted May 12, 2024, 1:39 PM EDT
Hello Team,
This format is wroking but my only problem here is if I want to sum up FeesPaid, I get the below error as shown in the shot below