Can anyone explain how on earth the following statement can generate
System.InvalidOperationException: The value null not be assigned a member of type System.Boolean since it is a value type that cannot have the value null (freely translated from Swedish (see also)).
if (user.Friends.Count() == 0)
user is a User and Friends is an IEnumerable<User>
.
Update: Friends is returned from a linq to sql call and is actually a WhereSelectEnumerableIterator
. It is empty in this case so I had expected the above to evaluate to true. In cases when Friends is not empty this works fine. So for some reason when it's empty havoc descends, it'd be nice to know why, but I guess what I'm really asking is, what's the workaround?