5
I have these 2 related classes, and the requested class has a Collection of "Itenspedidos"...
The Request class:
public class PedidoDTO
    {
        public int pedidoID { get; set; }
        public int codigo { get; set; }
        public DateTime data { get; set; }
        public int clienteID { get; set; }
        public virtual ClienteDTO Cliente { get; set; }
        public virtual IEnumerable<ItemPedidoDTO> itensPedidos { get; set; }
    }
And the Itempedido class:
 public class ItemPedidoDTO
    {
        public int itemPedidoID { get; set; }
        public int quantidade { get; set; }
        public decimal preco { get; set; }
        public int porcentagemDesconto { get; set; }
        public int pedidoID { get; set; }
        public virtual PedidoDTO pedido { get; set; }
        public int produdoID { get; set; }
        public virtual ProdutoDTO produto { get; set; }
    }
My question is this:: How do I persist the data so that the Itempedido entity automatically receives the foreign key?
In the project I use: Code first, EF6, Migrations, generic repositories, implementation and mapping repositories with Fluent Api.
I do not know if it is necessary to map the foreign entity (
ItemPedidoDTO) to the dependent entity (PedidoDTO). It is sufficient thatPedidoDTOhave an aggregationICollection<ItemPedidoDTO>virtual and public.– Marcelo Shiniti Uchimura
@Marceloshinitiuchimura really shouldn’t have to. But I prefer to map to be clear, mainly to inform the bank how will work the foreign key, in this example I put the "Ondelete Cascade".
– Thiago Araújo