I have 2 related tables, which are Assemblies and Parts.
My Assembly class:
public class Assembly{
public int Id { get; set; }
public string No{ get; set; }
public string Name { get; set; }
public int? ParentId { get; set; }
public Assembly Parent { get; set; }
public List<Assembly> Children { get; set}
public List<Part> Parts { get; set; }
}
My Part class:
public class Part{
public int Id { get; set; }
public string No { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public int AssemblyId { get; set;}
public Assembly Assembly { get; set; }
}
What am I doing is, first I'm creating Assemblies in a controller. Then when I create an Assembly, a file upload page is opening, then I upload an Excell files and map the excell data to my Part Object as a reference to my Assembly object.(Every parts AssemblyId will be the AssemblyId comes from route)
But there is a huge problem with this, because most of the Assemblies have the same Part or Parts in its Parts list.
For example, lets say there is a part, Part No : 555 , Part Name : Axle.
And lets assume that Im going to create 5 Assembly in my project. And every Assembly will going to have data imported from different excell files.
And each excell contains the same Part which its Part No : 555 and Part Name: Axle but obviously with different AssemblyId(FK).
But still in my Database there are so many Parts which has the same information with its duplicates but the little difference is that their AssemblyId column is different and referencing to another Assembly in the AssemblyId.
What I'd like to achive is to avoid from this situation...
I don't want to repeat my data. Actually I think a solution but Im not sure that its a good solution.. I might do a "if" statement and check, while uploading data from excell, if a Part with those information aleady exists in the database I might not upload that specific row to the table, and use the part which is already exist. But I think this will slows down my project.
I hope I've asked it clearly..