2
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 item table and table photos. It is possible to do this within the same _Dbcontext?
I tried it the way down and it didn’t work.
_DbContext.Item.Add(new Entidade.Item
{
Id = item.Id,
Nome = item.Nome,
fotos = item.Fotos
});
_DbContext.SaveChanges();
Any hint?
Thank you
It worked!!! Thank you very much Zignd. :)
– Thiago Rodolfo
In addition to marking as accepted, honor the answer also with a positive vote. ;) @Thiagorodolfo
– rubStackOverflow