graph - Taking advantage of the Entity Framework's many-to-many relationships when the joining table has an extra field -


a scenario:

in database have table joining customers , movies together, field specifying weight of relation. eg:

customersmovies   | -customerid   | -movieid   | -weight  

if had first 2 fields, entity framework recognise many-to-many relationship , able call customer.movies , movie.customers. third field, relationship broken.

ideally, love able go customer.movies[0].weight or similar return joining parameter. if not supported, still many-to-many relationship other functions.

is supported within entity framework? create 2 tables, customersmovies (which joins 2 tables) , customermovieweights table specifies weight given customer , movie, redundant data isn't ideal.

kind regards, harry

if dropped weight column junction table, need map customers , movies table.

if not, need map 3 tables: customer, customermovies , movies.

but of course, not able this:

var customer = ctx.customers.first(); var customermovies = customer.movies; 

you have this:

var customer = ctx.customers.first(); var customermovies = customer.customermovies.movies; 

because customer not have direct navigational property movie - have navigational property customermovie (and vice versa).

honestly though, go last idea. have customermovies table contain fk's (customerid, movieid), , "meta-data-like" table weights.

this way can map many-to-many in edmx.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -