Hello, I need help with an update using entity framework and one-to-many relationship. I think it's pretty basic, but I'm starting with EF and I can not solve the problem.
Artist and Telephone Artist entities, where an artist can have several phones.
public class Artista
{
public Artista()
{
Telefones = new List<TelefoneArtista>();
}
public int ArtistaId { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public virtual ICollection<TelefoneArtista> Telefones { get; set; }
}
public class TelefoneArtista
{
public int TelefoneArtistaId { get; set; }
public string Numero { get; set; }
public int ArtistaId { get; set; }
public virtual Artista Artista { get; set; }
}
How do I update?
I tried this way but it did not work.
public void Update(Artista obj)
{
Db.Entry(obj).State = EntityState.Modified;
Db.SaveChanges();
}
Thanks in advance!