以下のメソッドが WCF サービスにあると仮定しましょう。UI は Status オブジェクトのインスタンスを取得し、このメソッドを使用してサービスへの後続の呼び出しを行います。期待どおりにステータスをユーザーに割り当てる代わりに、ステータスを挿入しようとします。私は何を間違っていますか?
void Method(Status status)
{
//not sure if this is even needed, the status never changed
context.Statuses.ApplyChanges(status);
//get the first user from the database
User user = context.Users.Where(u => u.Id = 1).First();
//set user status to some existing status
user.Status = status;
//this throws an exception due to EF trying to insert a new entry
//into the status table, rather than updating the user.StatusId column.
context.SaveChanges();
}