I have these 2 related classes, and the requested class has a Collection of "OrderItems" ...
The Order 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 OrderPrice 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: How do I persist the data in a way that the RequestMessage automatically receives the foreign key?
In the project I make use of: Code first, EF6, migrations, generic repositories, implementation repositories and mapping with Fluent Api.