Reputation: 1236
I have multiple tables and from that I want to get count from tables on specific ID from the query like below :
var jobsPostList = (from jobposting in reslandEntities.JOB_POSTING
join skill in reslandEntities.SKILL on jobposting.SKILL_ID equals skill.ID
from req in reslandEntities.REQUIREMENT_POSTING
where jobposting.POSTED_BY_ID == RES_ID && jobposting.POSTED_BY == "CLIENT"
&& jobposting.IS_DELETED == "N"
&& jobposting.STAT!="DRAFT"
&& req.JOB_ID==jobposting.ID
select new PostJobModel
{
ID = jobposting.ID,
JOB_ID = jobposting.JOB_ID,
POST_TITLE = jobposting.TITLE,
POST_DT = jobposting.POST_DT,
POST_END_DT = jobposting.POST_END_DT,
TECH_SKILLS = skill.TECH_SKILLS,
POSITIONS_CNTS = jobposting.POSITIONS_CNT,
DURATION = jobposting.DURATION,
LOCATION = jobposting.LOCATION,
STAT = jobposting.STAT,
DT_CR = jobposting.DT_CR,
SUB_COMP_COUNT = reslandEntities.REQUIREMENT_POSTING.Where(m => m.JOB_ID == jobposting.ID).Select(m => m.COMP_ID).Count(),
COMP_COUNT = companyCount,
CAND_COUNT = reslandEntities.SUBSCRIBER_RESOURCE_SUBMISSION.Where(m=>m.CLIENT_JOB_POSTINGID==req.ID).Select(m=>m.RES_ID).Count()
}).Distinct().ToList();
I Want to get COUNT from "REQUIREMENT POSTING" table and another table "SUBSCRIBER_RESOURCE_SUBMISSION" table, I have tried like above but not getting proper result, getting multiple rows instead of one row. Please help me anyone.
Upvotes: 1
Views: 1524
Reputation: 888
I think this will work for you...
var jobsPostList = (from jobposting in reslandEntities.JOB_POSTING
join skill in reslandEntities.SKILL on jobposting.SKILL_ID equals skill.ID
join grpComp in
(
from jobsent in reslandEntities.REQUIREMENT_POSTING
group jobsent by jobsent.JOB_ID into grp
select new { grp.Key, count = grp.Select(m => m.COMP_ID).Count() }
) on jobposting.ID equals grpComp.Key
let result = (
from sub in reslandEntities.SUBSCRIBER_RESOURCE_SUBMISSION
join req in reslandEntities.REQUIREMENT_POSTING on sub.CLIENT_JOB_POSTINGID equals req.ID
where req.JOB_ID == jobposting.ID
select sub.RES_ID
)
where jobposting.POSTED_BY_ID == RES_ID && jobposting.POSTED_BY == "CLIENT"
&& jobposting.IS_DELETED == "N"
&& jobposting.STAT!="DRAFT"
select new PostJobModel
{
ID = jobposting.ID,
JOB_ID = jobposting.JOB_ID,
POST_TITLE = jobposting.TITLE,
POST_DT = jobposting.POST_DT,
POST_END_DT = jobposting.POST_END_DT,
TECH_SKILLS = skill.TECH_SKILLS,
POSITIONS_CNTS = jobposting.POSITIONS_CNT,
DURATION = jobposting.DURATION,
LOCATION = jobposting.LOCATION,
STAT = jobposting.STAT,
DT_CR = jobposting.DT_CR,
SUB_COMP_COUNT = grpComp.count,
COMP_COUNT = companyCount,
CAND_COUNT = result.Count()
}).ToList();
Upvotes: 3