views:

205

answers:

1

I have Master1 and Sub1 and a another called Master1Sub1_Map which contains foreign keys to the Master1 and Sub1 objects. There are multiple ID's from Sub1 that are associated with a single id in Master1.

If I want to see all the Sub1 records that are assigned to a specific Master1.ID how do I go about doing that with the SubSonic objects? I can do it using SqlQuery and IN with a nested select, but is there a better way since the map table is using foreign keys? It would be nice to have a Sub1Collection returned.

I see some references in TableSchema but I am not sure what will do what I am looking for.

+2  A: 
Sub1Collection subs = DB.Select().From<Sub1>()  
  .InnerJoin(Master1Sub1_Map)  
  .InnerJoin(Master1)  
  .Where(Master1.Columns.Id).IsEqualTo(1)  
  .ExecuteAsCollection<Sub1Collection>();
Adam
Thanks for the help!
Scott