Link to home
Start Free TrialLog in
Avatar of Mauro Cazabonnet
Mauro CazabonnetFlag for United States of America

asked on

C# Entity Framework Join

How can I change the joins to left joins

var query = (from u in db.tblvCenterHostsUnassigneds
                             join cms in db.tblvCenterHostNames on u.HostNameid equals cms.HostNameID
                             join vcdc in db.tblvCenterDataCenters on u.VCDC equals vcdc.DataCenterID
                          select new { u.HostNameid, cms.HostName, vcdc.DataCenterName,u.VCName,u.Tier});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A more readable query is shown below:
var query = (from u in db.tblvCenterHostsUnassigneds
             from cms in db.tblvCenterHostNames
		.Where(cm => u.HostNameid = cm.HostNameID)
                .DefaultIfEmpty() // <== makes join left join              
             from vcdc in db.tblvCenterDataCenters
		 .Where(v => u.VCDC equals v.DataCenterID)
                .DefaultIfEmpty() // <== makes join left join              
	     select new {
			     u.HostNameid, cms.HostName, vcdc.DataCenterName, u.VCName, u.Tier
	    }
);

Open in new window