Dlaczego MSSQl tworzy duplikacj tabeli pośredniej

0

Witam, zajmuje się tworzeniem modelu bazy danych za pomocą Code First i natrafiłem na pewien problem... Mianowicie tworze relacje Many to Many i niepotrzebnie tworzy mi się duplikat tabeli pośredniej. Z poziomu MSSQL mam tabele** OrderProduct1 i OrderProducts wtf?** Czy jest na to jakis sposób, aby to zablokować?

 
    public class Order
    {

        public int OrderID { get; set; }
        public DateTime DateOrder { get; set; }     
        public bool IfAcceptedOrder { get; set; }   
        public DateTime DateShipment { get; set; }  
        public bool IfOrderSuccesed { get; set; }   
        public DateTime DateRealizationOrder { get; set; }  
        public ApplicationUser User { get; set; }

        public virtual ICollection<Product> Products { get; set; }
        public virtual ICollection<OrderProduct> OrderProducts { get; set; }
  
    }


    public class Product
    {
     
        public int ProductID { get; set; }
        public int CategoryID { get; set; }
        public int PriceID { get; set; }
        public string ProductName { get; set; }
        public string Producer { get; set; }
        public string Description { get; set; }
        public bool Available { get; set; }
        public bool Promotion { get; set; }

        public virtual Price Prices { get; set; }
        public virtual ICollection<OrderProduct> OrderProducts { get; set; }
        public virtual ICollection<Image> Images { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
    }

    public class OrderProduct
    {
        public int OrderProductID { get; set; }
        public int OrderID { get; set; }
        public int ProductID { get; set; }
        public int Quantity { get; set; }
        public decimal UnitPrice { get; set; }

        public virtual Product Products { get; set; }
        public virtual Order Orders { get; set; }
    }

0

A o co pytasz? Bo piszesz o MSSQL, a zamiast kodu SQL dałeś C#.

0

do rzeczy za pomocą migracji robię update modelu bazy danych, który następnie jest odzwierciedlony w MSSQL. I jest taki o to mały krzaczek ze tabele pośrednią OrderProducts tworzy mi podwójnie..

0

Ale to nie MSSQL tworzy, tylko Entity Framework. Poszukaj w tutorialu jak tworzyć powiązania n:m w EF.

0

znalazłem dwa podejścia jedno zaprezentowane powyżej, drugie natomiast można osiągnąć stosując fluent API. obie metody przetestowane i ten sam wynik...

1 użytkowników online, w tym zalogowanych: 0, gości: 1