Lightswitch – Query where no match exists in reference table

I’m building an internal IT inventory application in LightSwitch, and have been trying to add a screen that only shows software in the inventory that has not been assigned to hardware.

Lightswitch doesn’t allow the graphical query editor to select the “many” side of a relationship on a filter (as documented here), so this is something that must be done in code.

I struggled for a bit trying to make a Left Outer Join in Linq between my two entities, but eventually stumbled upon a post by the always helpful Yann Duran:

http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/664454f7-0b2e-409e-b57c-625180132c53/

What I needed was the C# syntax for his suggestion, which is reproduced here with my relevant entity name:

query = query.Where((a) => a.itinv_SoftwareAssignedHardwares.Any() == false);

This is created within a query on the itinv_Software entity.

 

Leave a Reply

Your email address will not be published.