Let's say I have a manufacturer which produces lots of models. Each model has several attributes, and these attributes should come in a certain sort order. Here is what I did before:
Table "ManufacturerModel" with
public virtual ICollection<VehicleAttribute> Attributes { get; set; }
Table "VehicleAttribute" with
public virtual ICollection<ManufacturerModel> Models { get; set; }
and finally ModelBuilder fluent api to connect these two tables so I get a 1:n relationship:
modelBuilder.Entity<ManufacturerModel>() .HasMany(mm => mm.Attributes) .WithMany(a => a.Models) .Map(mv => { mv.ToTable("Model_VehicleAttribute", SchemaNames.Config); mv.MapLeftKey("ManufacturerModel_Id"); mv.MapRightKey("VehicleAttribute_Id"); });
Works perfect. BUT: where do I put the SortOrder column? In my opinion it should be inside mapping table "Model_VehicleAttribute" so I can select a ManufacturerModel and get all Attributes in a sorted order. How can this be achieved?