私はcurrentAppointmentを予定に複製しようとしています。私の問題は、currentAppointmentにGUIDがあることです。新しい重複予定を作成しようとすると、次のエラーが表示されます。 'プロパティ' AppID 'はオブジェクトのキー情報の一部であり、変更することはできません。 '。オブジェクトの主要情報です。変更することはできません。
これはなぜ私がこのエラーを受けているのかを完全に理解していて、私はフィールドごとにフィールドを移動し、それらを一致させることができることを知っています(32フィールド)。しかし、任命 '新しいフィールドは、フィールドごとにフィールドを移動せずに。
Appointment currentAppointment = db.Appointments.Find(id);
Appointment appointment = currentAppointment;
appointment.AppID = Guid.NewGuid(); (where I get the error since I already have a guid from currentAppointment but would like appointment to have a new one.)
appointment.AgentID = 1;
appointment.StatusID = 13;
db.Appointments.Add(appointment);
[参照の種類](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types)(おそらく[値の種類](https ://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/value-types)も参照してください)。 'appointment'は' currentAppointment'によって表される同じオブジェクトへのポインタに過ぎないので、あなたはエラーを受け取ります。 'db'とは何ですか?それはエンティティフレームワークなのでしょうか? – Equalsk
Entity Framework –
おそらく、これを達成するために 'AsNoTracking'を使用することを検討できます。 https://stackoverflow.com/questions/15308747/entity-framework-5-deep-copy-clone-of-anentity –