Что не так?
От: varenikAA  
Дата: 21.12.20 04:02
Оценка:
пилю на асп нет коре:
public class Client {
        public int? ContactId { get; set; }
        public virtual Contact Contact { get; set; }
        public virtual ICollection<Contact> Contacts { get; set; }
}


  кидает исключение
The instance of entity type 'Contact' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.


Неужели ORM запрещает так делать?
☭ ✊ В мире нет ничего, кроме движущейся материи.
Re: Что не так?
От: Sharov Россия  
Дата: 07.01.21 13:56
Оценка: +1
Здравствуйте, varenikAA, Вы писали:

AA>пилю на асп нет коре:

AA>
AA>public class Client {
AA>        public int? ContactId { get; set; }
AA>        public virtual Contact Contact { get; set; }
AA>        public virtual ICollection<Contact> Contacts { get; set; }
AA>}
AA>


AA>
  кидает исключение
AA>The instance of entity type 'Contact' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.


AA>Неужели ORM запрещает так делать?


Что пытаетесь делать? Подозреваю, что пытаетесь добавить Сontact в model, при условии, что ICollection<Contact> уже
в находится в модели. Т.е. дважды пытаетесь добавить один и тот же контакт.
Кодом людям нужно помогать!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.