I'm trying to use code first to create a many-to-many relationship between two tables.
I have something that looks like the following.
public class Railroad
{
public int Id { get; set; }
// Other members...
public ICollection<StorageLocation> StorageLocations { get; set; }
}
public class StorageLocation
{
public int Id { get; set; }
public Provider Provider { get; set; }
// Other members
public ICollection<Railroad> Railroads { get; set; }
}
I read an article that described this being the correct way to do it. But when I try to build the migration, I get an error.
Unable to determine the relationship represented by navigation property 'Railroad.StorageLocations' of type 'ICollection'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Are you sure you're not on EF Core
?
this has been supported before but not now in EF Core:
See this
In previous versions of Entity Framework, this model definition was sufficient for EF to imply the correct type of relationship and to generate the join table for it. In EF Core it is necessary to include an entity in the model to represent the join table, and then add navigation properties to either side of the many-to-many relations that point to the join entity instead: