Relationship 1x1 (or not)

1

I have 2 entities:

Product Order and Product ...

Using the fluent API as I say to my entity Requested Item that it has a Product?

Note: The product entity can not have dependencies, although 1 product can be in several items. I do not want it to depend on an item. Request to exist ...

Product Class:

namespace DTO
{
    public class ProdutoDTO
    {
        public int produtoID { get; set; }
        public int codigo { get; set; }
        public string descricao { get; set; }
        public decimal preco { get; set; }
    }
}

Order Item Class:

namespace DTO
{
    public class ItemPedidoDTO
    {
        public int itemPedidoID { get; set; }
        public int quantidade { get; set; }
        public int porcentagemDesconto { get; set; }

        public int produdoID { get; set; }
        public virtual ProdutoDTO produto { get; set; }
    }
}
    
asked by anonymous 07.08.2018 / 17:41

1 answer

2

You can use the following code to map the one-way relationship:

modelBuilder.Entity<ItemPedidoDTO>().HasRequired(i => i.produto).WithMany();
  • HasRequired sets the product relationship to mandatory
  • WithMany () configures the relationship to be mandatory: many without many-side navigation property

If English is easy on you, consider doing a link on this link link

    
08.08.2018 / 01:50