I see strange behavior in my Entity Framework model. I have a query that looks like this:
var rows = ( from alarm in context.Alarms join temp in context.ListDetails on alarm.ListDetailId equals temp.ListDetailId into entries from entry in entries.DefaultIfEmpty() join read in context.Reads on alarm.ReadId equals read.ReadId join plate in context.Images on alarm.ReadId equals plate.ReadId where alarm.IActive == 1 && ! alarm.TransmittedAlarm where read.IActive == 1 where plate.IActive == 1 && plate.ImageTypeId == 2 select new { alarm, entry, read, plate } ).ToArray();
The query returns all columns in alphabetical order by column name. It turns out this column is NULL for multiple rows in the result set. When I expand the rows variable in the debugger, I see that the whole line is null!
EDIT: Some clarifications.
By "first column" I mean the first column of the first row, i.e. in "SELECT A, B, C FROM ...", I mean A. It just happens that the query that builds the Entity Framework returns all the columns of the combined result set in alphabetical order, and the first in alphabetical order is zero and is null for some lines.
This column is not a primary key; if it is a primary key, it cannot be null.
When the Entity Framework processes rows of returned data into objects, it looks at the value of the first column in each row. If this column is null, it returns null for the row, not an object with a property that matches this column set to null.
I do not believe that it has anything special with a left outer join; it just happens that my request uses one. However, I did not do any checks to verify this, so this is just an assumption.
Has anyone seen this before? Can anyone fix this?
Tony