A Linq Error: The null value cannot be assigned to a member with type System.Boolean which is a non-nullable value type.

Take over a project in half way, it’s base on asp.net MVC and use LinQ for data access layer.

When I try to add a new function in one class, and use LinQ to get one row data from a table, get below error:

The null value cannot be assigned to a member with type System.Boolean which is a non-nullable value type.

the LinQ is very simple:

When I go to the class found that one property is bool type from one column of table, but no exception control if the data is null, and in dbml schema layer it was defined as Bit NOT NULL for Server Data Type. That mean someone changed the table after this project was built.

Solution is change Nullable from False to True, save and build the project again.


Untitled

 

The following two tabs change content below.
Wang Weiqiang is a senior web developer, and professional on ASP.NET, MVC, C#, Python, SQL Server, HTML5, Javascript, also interesting in machine learning and related algorithm.

Latest posts by Wang Weiqiang (王维强) (see all)

Wang Weiqiang is a senior web developer, and professional on ASP.NET, MVC, C#, Python, SQL Server, HTML5, Javascript, also interesting in machine learning and related algorithm.

Posted in ASP.NET, C# Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Categories

Recent Posts

Related Posts