LINQ for SuperAdmin (Add the property count) -- join & count function

来源:互联网 发布:平面美工 招聘条件 编辑:程序博客网 时间:2024/05/29 03:18

LINQ Code

 //Search with linq            var TBsearch =                from tb in dc.Agencies                join tb1 in dc.Users on tb.idUser equals tb1.idUser                join tb2 in dc.AgencyOffices on tb.idAgency equals tb2.idAgency                join tb3 in dc.Agents on tb2.idOffice equals tb3.idOffice                join tb4 in dc.Properties on tb3.idUser equals tb4.idCreatedBy into ps                where                    (userempty || tb.idUser.ToString().Equals(idUser)) &&                    (agencyempty || tb.idAgency.ToString().Equals(queryagencyid)) &&                    (addressempty ||                        (tb1.AddressLine1 + tb1.AddressLine2 + tb1.AddressLine3).Contains(addrkeywordAr[0]) &&                        (tb1.AddressLine1 + tb1.AddressLine2 + tb1.AddressLine3).Contains(addrkeywordAr[1]) &&                        (tb1.AddressLine1 + tb1.AddressLine2 + tb1.AddressLine3).Contains(addrkeywordAr[2])                        )&&                    (nameempty ||                        (tb1.UserFName + tb1.UserSName + tb1.UserName).Contains(namekeywordAr[0]) &&                        (tb1.UserFName + tb1.UserSName + tb1.UserName).Contains(namekeywordAr[1]) &&                        (tb1.UserFName + tb1.UserSName + tb1.UserName).Contains(namekeywordAr[2])                         ) &&                    (startempty || tb1.UserFName.StartsWith(startwith)) &&                    (officeempty || tb.idAgency == oid_aid) &&                    (usertypeempty || tb1.idUserType.ToString().Equals(queryusertypeid))                select new {                     tb.idAgency,                    tb.PublicPwd,                    tb.idUser,                    tb1.Name,                    tb1.UserFName,                    tb1.UserName,                    Address=tb1.AddressLine1+tb1.AddressLine2+tb1.AddressLine3,                    pcounts = ps.Count(),                };

Call LINQ query Result

 listStr += "<td class='" + styleClass + "'>" + resultList.ElementAt(i).pcounts + "</td>";



原创粉丝点击