linq to sql - SQL Join Query taking long to complete -
i working on project require me join 4 tables. have written code it's taking forever finish. please help. ohhh have 121 000 entries in db
portfoliocollectiondatacontext context = null; context = datacontext; var logins = bkg in context.enquirybookings bkg.paid == true log in context.logins log.loginid == bkg.loginid enq in context.enquiries enq.enquiryid == bkg.enquiryid estb in context.establishments enq.establishmentid == estb.establishmentid select new { log.loginid, log.firstname, log.lastname, log.countryofresidence, log.emailaddress, log.telephonenumber, bkg.totalprice, estb.companyname }; string str = ""; foreach (var user in logins) { str += ("[name: " + user.lastname + " " + user.firstname + " - country: " + user.countryofresidence + " - phone: " + user.telephonenumber + " - email: " + user.emailaddress + " - booked from: " + user.companyname + " - spent: " + user.totalprice.tostring() + "]"); } return str;
use following query on linq
portfoliocollectiondatacontext context = null; context = datacontext; var logins = bkg in context.enquirybookings join log in context.logins on log.loginid equals bkg.loginid && bkg.paid == true join enq in context.enquiries on enq.enquiryid equals bkg.enquiryid join estb in context.establishments on enq.establishmentid == estb.establishmentid select new { str = "[name: " + log.lastname + " " + log.firstname + " - country: " + log.countryofresidence + " - phone: " + log.telephonenumber + " - email: " + log.emailaddress + " - booked from: " + estb.companyname + " - spent: " + bkg.totalprice.tostring() + "]" }; string output = string.join(", ", logins.tolist()); return output;
check query taking cursor on logins , paste query here. check estimated execution plan of query , paste here.
if using sql server, execution plan of query using sql server management studio, click on icon highlighted in image below.
Comments
Post a Comment