Query objects from lookup table from many to many

I have an Master1

and Sub1

and another one Master1Sub1_Map

that contains foreign keys for objects Master1

and Sub1

. There are several identifiers from Sub1

that are associated with one identifier in Master1

.

If I want to see all the entries Sub1

that are assigned to a specific one Master1.ID

, how can I do that with SubSonic objects? I can do this with SqlQuery and IN

with nested selection, but is there a better way since the map table uses foreign keys? It would be nice to return Sub1Collection.

I see some links in TableSchema

, but I'm not sure what will do what I'm looking for.

0


a source to share


1 answer


Sub1Collection subs = DB.Select().From<Sub1>()  
  .InnerJoin(Master1Sub1_Map)  
  .InnerJoin(Master1)  
  .Where(Master1.Columns.Id).IsEqualTo(1)  
  .ExecuteAsCollection<Sub1Collection>();  

      



+2


a source







All Articles