There are two tables:
- Master, with fields: MID, MField1, MField2
- Detail, with fields: DID, MID (the foreign key of Master), DField1, DField2
Classes are named exactly as tables, fields too. The collection of Detail records in the Master class is named "Details".
When I ask:
select * from MasterExtent as m, m.Details as d where m.MField1 = 'xx' and d.DField1 = 'yy'
I get a list of filtered (as expected) Master records. Every Master has all its Details; but I want only Details that have DField1 = 'yy'. Therefore I must scan all the collection to find Details I want. It is not comfortable and forces unneccesary reads form the database.
I want them to read, not to manipulate. Is it possible to obtain only a subset of Details? In my case I know that there will be only one Detail and I would like to reach it as: master.Details.
Searching just for Details:
select * from DetailExtent as d where d.DField1 = 'yy' and d.ms.MField1 = 'xx'
("ms" is the reference to Master)
is not a solution because in the real case relations are more complex and I cannot freely navigate in the backward direction.