Since my last post on Expressions I have finally managed to write the code to handle child-based security, where access to one or more of a child table gives access to a parent table.
I eventually realised that I could write my iterative code to drop down the relationship path e.g. Company.Partners.Customers and then build a .Count() sub-select for each one.
So for access to customer #1 I say:
inner query: .Customers.Where(p1 => p1.CustomerID==1)
outer query 1: .Partners.Where( p2 => p2.Customers.Where(p1=> p1.CustomerID==1))
outer query 2: .Companies.Where( p3 => p3.Partners.Where(
p2 => p2.Customers.Where(p1=> p1.CustomerID==1)))
Writing this code required an interative function but it worked. My only kludge in this code was when I had to obtain the .Select() method (by using .First() !).