entity framework - EF other way to Sum() new Column -
i got stuck on query calculate new column. cannot explain briefly see snippet code below.
from user in context.table select new { total = user.total, paid = user.paid, balance = //should total - paid assign result }
i have tried query
var result = in context.enrollmentrequests a.schoolyear == schoolyear select new { a.studentid, name = a.student.firstname + " " + a.student.middlename + " " + a.student.lastname, tuition = context.miscs.where(m => m.yearlevel == a.yearlevel && m.schoolyear == schoolyear && m.term == a.term && m.courseid == a.courseid) .select(ms => new { amount = ms.amount }) .union(context.studentcharges .where(s => s.yearlevel == a.yearlevel && s.schoolyear == schoolyear && s.term == a.term && s.courseid == a.courseid && s.studentid == a.studentid) .select(ss => new { amount = ss.amount })) .union(context.studentsubjecttakes .where(st => st.studentid == a.studentid && st.schoolyear == a.schoolyear && st.term == a.term && st.yearlevel == a.yearlevel && st.educationallevel == a.student.studentadvanceeducations.firstordefault().educationlevel) .select(st => new { amount = context.subjectofferedfees .where(f => f.subjectsofferedid == st.subjectsofferedid).sum(w => (decimal?)w.cost ?? 0) })) .select(f => f.amount).sum(), paymentmade = context.payments.where(p => p.schoolyear == schoolyear && p.term == a.term && p.studentid == a.studentid && p.paymentdes == "tuition fee").sum(sm => (decimal?)sm.amount), balance = tuition - paymentmade //does not exist on current context };
but doesn't work says not exist on current context.
how possible. thanks. helpful anyone.
balance = user.total - user.paid
Comments
Post a Comment