LINQ Join where the NULLS are returned Also
I am trying to do a JOIN in a LINQ statement where it brings back the NULLS also. My code is:
var linqQuery = (from r in orgServiceContext.CreateQuery("opportunity")
join a in orgServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals a["accountid"]
join c in orgServiceContext.CreateQuery("contact开发者_运维百科") on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
where ((EntityReference)r["new_channelpartner"]).Id.Equals(new Guid("c55c2e09-a3be-e011-8b2e-00505691002b"))
select new
{
OpportunityId = !r.Contains("opportunityid") ? string.Empty : r["opportunityid"],
CustomerId = !r.Contains("customerid") ? string.Empty : ((EntityReference)r["customerid"]).Name,
Priority = !r.Contains("opportunityratingcode") ? string.Empty : r.FormattedValues["opportunityratingcode"],
ContactName = !r.Contains("new_contact") ? string.Empty : ((EntityReference)r["new_contact"]).Name,
Source = !r.Contains("new_source") ? string.Empty : r["new_source"],
CreatedOn = !r.Contains("createdon") ? string.Empty : r["createdon"],
State = !a.Contains("address1_stateorprovince") ? string.Empty : a["address1_stateorprovince"],
Zip = !a.Contains("address1_postalcode") ? string.Empty : a["address1_postalcode"],
Eval = !r.Contains("new_colderevaluation") ? string.Empty : r.FormattedValues["new_colderevaluation"],
DistributorName = !r.Contains("new_channelpartner") ? string.Empty : ((EntityReference)r["new_channelpartner"]).Name,
ContactStreetAddress = !c.Contains("address1_line1") ? string.Empty : c["address1_line1"]
});
This pulls down the one record were contactid matches, but I also want it to bring down the records with a NULL contactid.
Any ideas how to do this?
Right outer joins are not supported in LINQ. Consider re-arranging your table sources so that you can do a left outer join using the DistinctIfEmpty extension method. Alternatively, you can use a LINQ version of SQL-Ansi82 instead of joins by writing all of the joins as where clauses.
精彩评论