Query filter on (property in related record of a record (sub record)

Topics: General, Writing modules
Oct 14, 2012 at 10:44 AM

I've have the following query: 

_orchardServices.ContentManager.Query("Club")
      .Where<ClubPartRecord>(c=> c.CityPartRecord.RegionPartRecord == null)

So "ClubPartRecord" has a related record "CityPartRecord" and "CityPartRecord" has a related record "RegionPartRecord". I get the following error with this query:

could not resolve property: CityPartRecord.RegionPartRecord of: Users.Models.Records.ClubPartRecord

As far I can see the normal query method can't query sub properties/records so it's returning this error. Queryhints doesn't solve this either. Could this be done using a normal Query or do I have to use a HQL query? Or is this not even possible with HQL and do I have to use a plain SQL query. Thanks!

 

Coordinator
Oct 14, 2012 at 7:40 PM

I think you can use a Join for that.

Developer
Oct 14, 2012 at 10:38 PM

prob something like this...

_orchardServices.ContentManager.Query("Club")
.Join<CityPartRecord>()
.Where(c=> c.RegionPartRecord == null)

???

Oct 15, 2012 at 6:23 PM

Nope already tried that but always same problem. Now i've done this using 2 separate queries but this is far from optimal.

Developer
Jan 19, 2013 at 12:50 PM

Perhaps try to query by Id instead of navigation properties, applying joins as needed.