Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating SQL bit column from Entity Framework
    primarykey
    data
    text
    <p>I'm having an issue updating a 'bit' column in a SQL database, using C# and Entity Framework.</p> <p>I have a 'Settings' table with a NOT NULL bit column named 'Active'. When I create a record in the table and specify 'Active' in code as 'true' or 'false', the record in the database that's created is accurate and the 'Active' column contains the correct value that was specified in code. When I update the record and change 'Active' from 'false' to 'true' in code, that works as well. However, when I update the record going from 'true' to 'false', the 'Active' column in the database still contains '1' (true).</p> <p>Is this a known issue? If so, is there a workaround? I've done a fair amount of research and was unable to find anything.</p> <p>Here's my update code:</p> <pre><code>public int UpdateSetting(SettingModel settingModel) { using (var db = new EfMyDB()) { // Create a new setting record with the ID of the record to update. Setting updatedSetting = new Setting { Id = settingModel.Id }; // Attach the record. db.Settings.Attach(updatedSetting); // Update the attached record. updatedSetting.Name = settingModel.Name; updatedSetting.Value = settingModel.Value; updatedSetting.Active= settingModel.Active; // Save the database changes. return db.SaveChanges(); } } </code></pre> <p>EF 'Active' column properties:</p> <p><img src="https://i.stack.imgur.com/L1etX.png" alt="Properties in the EDMX file for the &#39;Active&#39; column."></p> <p><strong>Versions</strong>: .NET 4.0, SQL Server 2008, Entity Framework 4.1</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload