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

你。 提交于 2019-11-29 16:21:16

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!