У меня проблема с этим кодом:
public class UtenteCollegamento
{
[Column("id"), Key]
public Int32 Id { get; set; } = 0;
[ForeignKey("idutente"), Required]
public Utente Utente { get; set; } = null;
[ForeignKey("idcollegamento"), Required]
public Collegamento Collegamento { get; set; } = null;
}
foreach (UtenteCollegamento u0 in lista)
{
context.Add(u0);
context.SaveChanges();
}
Например, если в первом элементе "lista" есть Id = 0, Utente.Id = 8 и Collegamento.Id = 5, я хотел быдобавить только новую строку в таблицу UtenteCollegamento, но мой код добавить новую Utente в таблицу Utente с Id = 8, новый Collegamento в таблицу Collegamento с Id = 5, а затем добавить строку в таблицу UtenteCollegamento (с Id = autoincrement, idutente= 8 и idcollegamento = 5).
Можете ли вы объяснить мне, что не так?Спасибо