I have the following query which should return no rows, but returns 4:
var testAgainst = db.MyForm1_hosps.Select(ta => ta.recordId == recordId);
If I use the following query I get zero rows as expected:
var testAgainst = from ta in db.MyForm1_hosps
where ta.recordId == recordId
select ta;
There ARE four rows in MyForm1_hosp but none match the recordId in my test.
The code doesn’t lie, so my understanding of LINQ is incorrect. Can someone explain to me why the first one returns 4 rows when it should return 0?
Your first query has a mistake. Change the
SelecttoWhere.Investigating your original query with
Select(ta => ta.recordId == recordId): This will return a sequence of booleans. If none of the records indb.MyForm1_hospshaverecordIdvalues matching the input, the results will all be false. If you have 4 records, you will get 4 false values. You have 4 results, but they are not of the type you think they are!