I have the EDMX:
How can i get sum of Amount of single Freelancer from FreelancerPayment table if has? All time FreelancerPayment table doesn't has Amount if the freelancer is new. I just want list of freelancers with their details and Total earn. I tried this:
var freelancers = (from fl in db.FreelancerLogins
join f in db.Freelancers
on fl.FreelancerID equals f.FreelancerID
select new
{
FreelancerID = fl.FreelancerID,
UserName = fl.UserName,
EmailAddress = fl.EmailAddress,
EmailConfirmed = fl.EmailConfirmed,
Status = fl.Status,
LogInTime = fl.LogInTime,
LogOutTime = fl.LogOutTime,
Picture = f.Picture,
Title = f.Title,
Name = f.FirstName + " " + f.LastName,
Overview = f.Overview,
JoiningDate = f.JoiningDate,
BirthDay = f.BirthDay,
Rate = f.Rate,
Location = f.Location,
//Earn = (fp.Amount == null ? 0 : fp.Amount)
Earn=(
from fla in db.Freelancers
join apl in db.AppliedJobs
on fla.FreelancerID equals apl.FreelancerID into apll
from ap in apll.DefaultIfEmpty()
join jo in db.JobOffers
on ap.AppliedJobID equals jo.AppliedJobID into joo
from jobo in joo.DefaultIfEmpty()
join c in db.Contracts
on jobo.OfferID equals c.OfferID into coo
from con in coo.DefaultIfEmpty()
join fpay in db.FreelancerPayments
on con.ContractID equals fpay.ContractID into fpayy
from fp in fpayy.DefaultIfEmpty()
select fp.Amount).Sum()
}).AsEnumerable();
return freelancers.AsEnumerable();
But it returns :
Amount same for all. How can i put where clause for specific freelancer?