In .NET Entity Framework, what is the best way to have a (custom) join table with extra attributes (other than ids) and/or associate this join table with others via separate model? In Ruby on Rails we can have a model for the join table, like:
Item.rb (model)
:has_many => :buyers, :through=>:invoice
...
Buyers.rb (model)
:has_many => :items, :through=>:invoice
...
Invoice.rb (model)
:belongs_to :item
:belongs_to :buyer
....
Then we can use: Item.first.buyers, Buyers.first.items and Buyer.create(:items=>Item.create(:name=>'random')) etc. just like when we use automated join table without model (using has_and_belongs_to_many).
In Visual Studio 2010’s “Add Association” dialog, if we select multiplicity as *(Many) there is no option to select a join table (with model). Is there a way to do it manually?
Yes, you can get something pretty close. I’m not quite sure how to set this up in the designer since I only work with codefirst.
Here’s an example:
Student -> StudentFloor <- Floor
The linking table:
Finally, the other side of the many-to-many: