I have an object model that contains a boolean MyBool and I have a table that contains a field MyField. I’m writing a linq-to-sql query that should returning a list of objects with MyBool set to true or false depending on if MyField has a value.
This is what I have so far:
var TheListOfObjects = (from thetable in MyDC.TheTable
....
select new MyObject()
{
MyBool = thetable.MyField.Contains("*")
}).ToList();
I the error: The null value cannot be assigned to a member with type System.Boolean which is a non-nullable value type. Doesn’t Contains return a bool?
What am I missing?
Thanks.
if you don’t want a nullable property in MyObject you can check for null when you are assigning