Dear, I have the following classes:
public class Foto
{
[Key]
public int Id { get; set; }
[StringLength(500)]
[Required(ErrorMessage = "Obrigatório")]
public string Nome { get; set; }
public int Item_Id { get; set; }
[ForeignKey("Item_Id")]
public virtual IEnumerable<Item> Item { get; set;
}
public class Item
{
[Key]
public int Id { get; set; }
[StringLength(500)]
[Required(ErrorMessage = "Obrigatório")]
public string Nome { get; set; }
}
I need to save in the table item and in the photos table. Is it possible to do this within the same _DbContext?
I tried the way below and it did not work.
_DbContext.Item.Add(new Entidade.Item
{
Id = item.Id,
Nome = item.Nome,
fotos = item.Fotos
});
_DbContext.SaveChanges();
Any tips?
Thank you