Expressions Expressed!

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() !).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s