+2  A: 

This largely depends on what framework you are using. It sounds like you are using LINQ-to-SQL, which is very literal about tables to objects. With Entity Framework, there is inbuilt support for many-to-many, in particular for the trivial case you've listed (a linking table with no additional properties). EF will generally spot this pattern, and hide the link table from the conceptual model (I can't remember, but it might need a spanning PK over the two FK columns).

Of course, this then goes sour if you want to add columns to the link-table; so in some ways I'd be tempted to leave it "as is".

With regards the where etc - how do you mean? You can do joins over the association, and you should be able to use Any etc; do you have a concrete example of what you want to do?

Marc Gravell
pretty much exactly what I showed. The goal is to add a tag to the artwork object. The only reasonable join is Many to Many. The only way I've seen so fart to do it with LINQ-to-SQL is to run a loop, creating artwork_subject objects, and binding them manually. What I find so odd, is that I can't even do an one to many join between the artwork and artwork_subjects tables (same applies to tagSubjects and artwork_subjects).
Justin Alexander
A: 

Yes. Instead of many-to-many use two many-to-one relationships:

Subject -*----1- ArtworkSubjectParticipation -1----*- Artwork
Dmytrii Nagirniak
Isn't that pretty much what the OP has already got in the screenshot?
Marc Gravell
you mean two one-to-many, right?
Kobi
it's the inverse of what I have. but the net result would mean that only one tag could be associated with one artwork, which is not the goal.
Justin Alexander
@Kobi, right. Corrected.
Dmytrii Nagirniak
@Marc, the picture on the original post shows RDBMS structure. The OO structure is different and is many-to-many.
Dmytrii Nagirniak
@Justin, no. With 2 many-to-one associations you can have implicit many-to-many association.
Dmytrii Nagirniak
+4  A: 

the way I have gotten M2M working in LINQ2SQL:

  1. drag the tables into the builder, like you're showing in the question
  2. remove the relationship between *artworks_subject* and artwork
  3. create a new relationship FROM *artworks_subject* TO artwork
  4. click on the new relationship to get its properties
  5. change the cardinality from OneToMany to OneToOne (because ManyToOne doesn't exist)
  6. open the Child Property section and change the Name field to make it singular (Artworks to Artwork)

now the tagSubject entity will have a collection of *artwork_subjects*, and the *artwork_subject* will have a property of type artwork called Artwork. so you can now make a LINQ expression like

var x = dbcontext.tagSubjects.Single(s=>s.name=="Landscape").
    Artwork_Subjects.
    Select(as=>as.Artwork.Name);
Mike Jacobs
+2  A: 

Found the solution myself. For automated relationships to work, both tables need primary keys (oops). Notice artworks_subjects is missing the PK symbol.

Justin Alexander