I have an odd linq subquery problem.
Given the following data structure:
Parents children
------- --------
Id id
ParentId
Location
Hasfoo (obviously this is not a real structure, but close enough for this example)
I can run this query and get the desired result:
bool b = (from p in Parents from c in Children where p.Id == 1 && c.ParentId == p.Id && c.Location == "Home" select c.HasFoo).SingleOrDefault();
So, if there is a child that has βHomeβ for parent ID 1, I get this βHasFooβ value for the child, otherwise I will get false, which is the default value for BOOL.
However, if I try to write a query, so I have a list of parent objects, for example:
var parentList = from p in Parents select new ParentObject { ParentId = p.ParentId, HasHomeChildren = p.Children.Count(c => c.Location == "Home") > 0, HasHomeChildrenWithFoo = (from c in p.Children where c.Location == "Home" select c.HasFoo).SingleOrDefault() }
I get the following error when iterating through a list:
The null value cannot be assigned to a member with type System. Boolean which is a non-nullable value type.
I do not see where this "zero" value comes from.
source share