Entity Framework database mapping relationships (Duplicate creation using Seed() method)

前端 未结 1 2059
孤独总比滥情好
孤独总比滥情好 2020-12-21 19:16

I created a post with an issue and another issue. These can be looked at for references but i consider them as handled.

My question arising from these issues and the

相关标签:
1条回答
  • I fixed my problem by redesigning the model. I have added a additional Entity ProductForSupplier which holds the relation of a Product & Supplier and a Productnumber.

    public class ProductForSupplier:BaseEntity
    {
        public string ProductnumberValue { get; set; }
    
        [Required]
        public Product Product { get; set; }
    
        [Required]
        public Supplier Supplier { get; set; }
    }
    

    Added a Entity ProductsForContract which will hold the amount of a Product-Supplier relation for 1 contract:

    public class ProductsForContract
    {
        public int ProductsForContractId { get; set; }        
        public int Amount { get; set; }
        public ProductForSupplier ProductForSupplier { get; set; }
        public Contract Contract { get; set; }
    }
    

    And the Existing Entity ProductSupplierForContract becomes:

    public class ProductSupplierForContract:BaseEntity
    {
        public ICollection<ProductsForContract> ProductsForContract { get; set; }
    
        [Required]
        public Contract Contract { get; set; }
    }
    

    This gives me the flexibility to keep relations of any kind between the entities and also has taken care of the duplicate (which i still don't know the cause of).

    0 讨论(0)
提交回复
热议问题