views:

36

answers:

1

Changes to nullable bool properties are not saved back to the db in EF4 however other fields which are nullable are updating without any issues. For example, if I execute simple query similar to the following:

EmployeeSurvey employeeSurvey = context.EmployeeSurveys.SingleOrDefault(s => s.EmployeeSurveyID == 60);

employeeSurvey.EmployeeSmokes = true; 
employeeSurvey.OtherComments = "Test comment";

context.SaveChanges();

The OtherComments changes are successfully saved back to the db however the EmployeeSmokes property changes are not. The EmployeeSmokes property is a bool? and other nullable boolean fields have the same issue.

Additionally, the problem only occurs when changing/updating existing EmployeeSurvery records - all properties including EmployeeSmokes are successfully saved when creating/inserting new EmployeeSurveys.

I've also tried using the ApplyCurrentValues method as per this thread but unfortunately it hasnt helped.

Any ideas why this is happening?

A: 

What is the value of employeeSurvey.EmployeeSmokes in the Database? If it is true, EF will notice there is no change and omit it från the generated Update SQL since there is no change (you can verify this in the SQL Profiler).