Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 01, 2010 11:21 PM by PaulBlamire
Feb 01, 2010 07:54 PM|LINK
The following goes wrong.
if (user.Friends.Count() == 0)
It throws 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
Part of the answer is that I expect user.Friends to be empty. It is a WhereSelectEnumerableIterator returned from a linq to sql call and when it's not empty the above works fine.
(Also open on
Feb 01, 2010 10:36 PM|LINK
this isn't a MVC discussion - I think it is a L2S or EF discussion. And maybe the count of friends is null when performing SQL translate - and therefore can not be translated ...
And maybe your Friends have a bool property ...
Feb 01, 2010 11:21 PM|LINK
if (user.Friends == null || user.Friends.Count()==0)
Or add a public partial class User and add a has friends property
public bool HasFriends
return (Friends != null && Friends.Any())