public Nullable<bool> BROUGHT { get; set; } // EDMX generate this code, so I can not change this
I want to null check for the BROUHGT (DB) column.
so I write code like
if (table.BROUGHT != DBNull.Value && Convert.ToBoolean(table.BROUGHT)){..}
but the error message say,
Error 2 Operator '!=' cannot be applied to operands of type 'bool?' and 'System.DBNull' ...
How I null check for that column?
Thank you!
Entity Framework is an ORM, and it’s shiedling you from having to think about
DBNull.Value. So just check againstnulllike you would in other C# code:Not that since it’s a nullable type, to get the actual
boolvalue you have to either use the.Valueproperty (as above) or cast it to abool.