Consider the case where i need a ProductPartRecord type and a ManufacturerPartRecord type.
In the fist type i need to know who’s the manufacturer of this part, hence it would be convenient to use a property of type ManufacturerPartRecord.
In the second type i would like to know the products this manufacturer makes, hence it would be convenient to have a property of type IList.
Apparently it is a 1 to many relationship.
Is this a bad practice to put Records in Records and is this even possible, because i’m facing troubles implementing it?
It is possible. And here’s how to do it:
ProductPartRecordwhich is of typeintand the name should beManufacturerPartRecord_Idassuming thatIdis the name of primary key inside theManufacturerPartRecordtable.SchemaBuilder.CreateForeignKey("Product_Manufacturer", "ProductPartRecord", new[] { "ManufacturerPartRecord_Id" }, "ManufacturerPartRecord", new[] { "Id" });ManufacturerPartRecordmodel class, you should add a new property which you’ll use for list of products –public virtual IList<ProductPartRecord> ProductPartRecords { get; set; }ProductPartRecordmodel class, you should add a new property which you’ll use to get manufacturer –public virtual ManufacturerPartRecord ManufacturerPartRecord { get; set; }It should be all set now to automatically get manufacturer for you products and vice versa.
If you don’t want this to happen automatically, you should create a service class which will get
IRepository<ManufacturerPartRecord>orIRepository<ProductPartRecord>via constructor injection and handle getting and saving lists yourself.