The problem is that you need to get columns from both: address and accommodation.
So I've taken some time to examen possible solutions here. My approach would be to get the subtree and query it using LINQ.
Here is what you need to to do.
Get the whole sub-tree underneath your folder. Please note we get only columns we need and specific types.
var listResult = DocumentHelper.GetDocuments()
.Path("/FolderPath/ ", PathTypeEnum.Children)
.Type("custom.Accommodation", q => q.Columns("ID", "Name")) // type specific
.Type("custom.Address", q => q.Columns("Town", "Longitude", "Latitude")) // type specific
.Columns("ClassName", "NodeId", "NodeParentID", "DocumentId") // shared for all types
.OnSite("your site")
.Culture("en-Us")
.ToList();
Cache it. So every time you search for a new town you will not query DB
Use LINQ to get what need
var obj = listResult.Where(x => x.ClassName == "custom.Address" && x.GetValue("Town") == "London")
.Select(address => {
var accomodation = listResult.Where(p => p.ClassName == "custom.Accommodation" && p.NodeID == address.NodeParentID).FirstOrDefault();
return new
{
ID = accomodation.GetValue("ID"),
Name = accomodation.GetValue("Name"),
Town = address.GetValue("Town"),
Longitude = address.GetValue("Longitude"),
Latitude = address.GetValue("Latitude"),
};
})
It is not the final code, but that should give the idea how to approach it.