c# - I need Linq to sql queries with join and count -
i need count how many singles of 1 matchmaker in tbluserregistration table. use following code,in code if codition filtering grid record. please replay me fastly.
private iqueryable chanims { { entitiesmodelmx dbcontext = new entitiesmodelmx(); //var query = p in dbcontext.tblshadchanims // p.confirmed == true || p.status != null // orderby p.shadchanimid descending // select p; var query = p in dbcontext.tblshadchanims join u in dbcontext.tbluserregistrations on p.shadchanimid equals u.shadchanid usercount orderby p.shadchanimid descending select new { p, singles = usercount.where(usr => usr.shadchanid !=0).count() }; if (txtfirstnamefilter.text.trim().length > 0) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.p.firstname.contains(txtfirstnamefilter.text.trim())); } if (txtlastnamefilter.text.trim().length > 0) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.lastname.contains(txtlastnamefilter.text.trim())); } if (txtphonefilter.text.trim().length > 0) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.phone1.contains(txtphonefilter.text.trim())); } if (!ddlstatus.selectedvalue.equals("all")) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.status == (int?)int.parse(ddlstatus.selectedvalue)); } if (txtemailfilter.text.trim().length > 0) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.email.contains(txtemailfilter.text.trim())); } if (!drpgender.selectedvalue.equals("all")) { query = (iorderedqueryable<maindatamx.tblshadchanim>)query.where(p => p.ismale == (bool?)bool.parse(drpgender.selectedvalue)); } return query; } }
above code not working.please reply back.
just use count grouping, please check following links:
group , count items linq groupby , count
hope in use :)
Comments
Post a Comment