We're looking at upgrading our dinosaur of EF 4.2 this week to EF 6.0.2 (Code First). For the most part, aside from some namespace changes, everything works, with one exception.
Using EF 4.2, one particular many-to-many relation had a specific join table name expected. EF 6 expects a different one.
Here is the relevant portions of code
public class MyDbContext : DbContext {
/* some unrelated collections*/
public IDbSet<DBFoo> Foos { get; set; }
/* some unrelated collections */
public IDbSet<DBBar> Bars { get; set; }
/* some unrelated collections */
}
public class DBFoo {
/* DBFoo's properties */
public virtual ICollection<DBBar> Bars { get; set; }
}
public class DBBar {
/* DBBar's properties */
/*some unrelated navigation properties (some single, some collections)*/
public virtual ICollection<DBFoo> Foos { get; set; }
/*more unrelated navigation properties*/
}
It's important to note that the "unrelated" properties mentioned are other entities, but themselves have no references to "DBFoo".
Now, in EF 4.2, the join table between these two entities was expected to be DBBarDBFoos
. This was without any configuration in the model builder or context or by using any data annotations.
After upgrading to EF 6.0.2, the join table is expected to be DBFooDBBars
. Why?
Note: I have "fixed" this issue by using the fluent API to bind the relationship to its proper table. What I want to know is why this table(and only this table) changed in it's convention.
Ninja Edit - rearranging the property declaration in the DBContext had absolutely zero effect.