I have a Document
table and a Tenant
table in my database, with a Document_Tenant
table to relate the two. I'm trying to get a selection of all Documents
, with related Tenants
, if any. That should be a left join between Document
and Document_Tenant
and an inner join between Document_Tenant
and Tenant
, so I followed Entity framework left join to get this code:
var combinedQuery = from doc in DocumentProvider.GetDocuments()
join dt in CustomTableItemProvider.GetItems<Document_TenantItem>()
on doc.ItemID equals dt.Document_ID into ddt
from x in ddt.DefaultIfEmpty()
join t in TenantProvider.GetTenants()
on x.Tenant_ID equals t.ItemID // joined tenants
select new { doc, t.Tenant_ID };
When that query executes, though, I get a NullReferenceException. I'm not sure why.
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.at lambda_method(Closure , <>f__AnonymousType37
2 , <>f__AnonymousType36
2 )
at System.Linq.Enumerable.d__233.MoveNext()
2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
1 source)
at System.Linq.Enumerable.Count[TSource](IEnumerable