我有 2 个实体对象“人员”和“研讨会”。关系 - 多对多。一个项目包括 - EF4.0/STE、WCF 和 WinForms。
当我尝试将人员添加到研讨会时
public void AddPersonsToSeminar(Seminar seminar, List<Person> persons)
{
using (T3EntitiesConn context = new T3EntitiesConn())
{
if (seminar != null)
{
context.Seminar.Attach(seminar);
foreach (Person person in persons)
{
if (!seminar.Person.Any(p => p.ID == person.ID))
{
seminar.Person.Add(person);
context.Seminar.ApplyChanges(seminar);
}
}
context.SaveChanges();
我有例外 -
The property 'ID' is part of the object's key and cannot be changed. Changes to key properties can only be made when the object is not being tracked or is in the Added state.
请解释如何解决它谢谢