我添加了一个新列IsForceLogOff(数据类型 = 位)。当我以通常的方式更新表格时,除了新添加的 bool 列之外,所有内容都会更新。
public static UserErrorStatus UserUpdate(User user, Company company)
{
UserErrorStatus status = UserErrorStatus.Error;
using (OAPDataLayerEntities DbEntity = GetDBContext())
{
try
{
using (TransactionScope transaction = new TransactionScope())
{
user.IsForceLogOff = true;
DbEntity.Users.Attach(user);
DbEntity.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
DbEntity.SaveChanges();
transaction.Complete();
DbEntity.AcceptAllChanges();
status = UserErrorStatus.Success;
}
}
}
}
创建表语句:
CREATE TABLE [dbo].[User]
(
[UserID] [int] IDENTITY(1,1) NOT NULL,
[AddressID] [int] NULL,
[AccountTypeID] [int] NOT NULL,
[StaffID] [int] NULL,
[SalutationID] [int] NULL,
[FirstName] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
[EmailAddress] [nvarchar](100) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[SecurityQuestionID] [int] NOT NULL,
[SecurityAnswer] [nvarchar](50) NOT NULL,
[PhoneNumber1] [nvarchar](50) NULL,
[PhoneNumber2] [nvarchar](50) NULL,
[Fax] [nvarchar](50) NULL,
[CompanyID] [int] NULL,
[DateCreated] [smalldatetime] NOT NULL,
[DateModified] [smalldatetime] NOT NULL,
[DateLastLogin] [smalldatetime] NOT NULL,
[UserIDModified] [int] NULL,
[StatusID] [int] NOT NULL,
[Notes] [ntext] NULL,
[IsForceLogOff] [bit] NOT NULL
)
参考上面的sql
