I have 2 chained LINQ queries in a single method. The first takes a substring from table rows that have the form "Person XXXX-XXXX is marked as deleted" and extracts the XXXX-XXXX portion out and puts them into an object containing the XXXX-XXXX.
var ids = from m in _repo.GetMessages()
where m.tool == 7
select new IDs
{
ID = m.text.Substring(6, 11),
text = m.text
};
This returns data as expected. The ids then joins to a subsequent "results" query:
var results = from gs in _repo.GetSample()
join c in _repo.Getcenters() on gs.Iid equals c.Iid_c
join id in ids on gs.id equals id.ID
select new Results
{
c_id = c.id,
iid_d = gs.Iid_d,
Id = gs.id,
Num = gs.num,
sts_dt = c.sts_dt,
store_dte = gs.Store_dte,
quantity = gs.Quantity
};
The query in this form returns the data expected, though I need to add a where clause to the results query. When I add a where clause that references any of the data objects in the query, the output produces "Object reference not set to an instance of an object." Without the where clause things look fine.
My first thought was that null items existed in first dataset, so I added a != null clause and it had no effect. Then I tried replacing the join with ID with a Contains(ID) statement and that didn't change things. Since I've written numerous linked LINQ queries before and chained them in this manner with no problem, my guess is that the join on the ID object may be causing something strange. Does anyone have any ideas on how to add where clauses to this without producing that error? Thank you!