【发布时间】:2013-03-25 19:49:46
【问题描述】:
我在使用 C# 和实体框架更新 SQL 数据库中的“位”列时遇到问题。
我有一个“设置”表,其中包含一个名为“活动”的 NOT NULL 位列。当我在表中创建记录并在代码中将“活动”指定为“真”或“假”时,所创建的数据库中的记录是准确的,并且“活动”列包含代码中指定的正确值。当我更新记录并将代码中的“活动”从“假”更改为“真”时,它也可以正常工作。但是,当我将记录从“true”更新为“false”时,数据库中的“Active”列仍然包含“1”(true)。
这是一个已知问题吗?如果是这样,是否有解决方法?我做了相当多的研究,但找不到任何东西。
这是我的更新代码:
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();
}
}
EF 'Active' 列属性:
版本:.NET 4.0、SQL Server 2008、Entity Framework 4.1
【问题讨论】:
标签: c# sql-server-2008 entity-framework