Reputation: 3
I am querying through linq to a SQL Azure database. When a new company is added the site redirects the user to display the company just added. It also provides an ID in a query string.
The statement being used is:
var Result = (from d in company.Companies
join c in company.originalSources on d.originalSource equals c.ID
join f in company.revenues on d.turnover equals f.ID
join g in company.recordTypes on d.type equals g.ID
where d.ID == Convert.ToInt32(Request.QueryString["ID"])
select new { d, c, f, g }).First();
However it is returning that the sequence contains no elements. i have used a breakpoint to ensure that the ID query string has the correct number and that the record exists so I cannot work out why it is not returning the record.
Upvotes: 0
Views: 1338
Reputation: 3660
The join operator performs an inner join. It won't return any results if either originalSources/revenues/recordTypes is null. Use a left outer join by using the 'into' operator as explained here: http://msdn.microsoft.com/en-us/library/bb397895.aspx
Upvotes: 1