Hi all, apologies if this has been discussed elsewhere; I did look but couldn’t find anything.
I have a pretty large graph to store in an SQL Server database; it maps accountability within large organisations. One ‘party’ might be accountable to many other parent parties, who in-turn are also accountable to other parties etc. At the moment I have an adjacency list model. A very much simplified example of the schema is as follows:
Party
- ID (PK)
- Name
- Etc
Accountability
- ParentPartyId (PK, FK)
- ChildPartyId (PK, FK)
- AccountabilityTypeID
This is all very well. Possibly not the best way to store a graph? But I don’t know of a better one (If it were a hierarchy, I’d use a nested set). In order to speed things up a bit and save on round trips to the database, I’m actually holding the entire accountability model (data from the accountability table, mapped on to an object) in the application’s cache. That way I can efficiently traverse it in memory. However, this object only stores the accountability, not the actual parties themselves - to do so take up far too much memory (the graphs can be huge and the party objects are large). My problem is with deciding on the most efficient way of retrieving the party data. For example, one of the more common operations will be to retrieve all parties that are accountable to a particular ‘parent’ party, both directly and indirectly (including those accountable to an accountable child and so on).
One thing I can do is traverse my in-memory accountability model collecting all of the accountable child ids and then create a predicate expression to retrieve a collection of parties with those Ids. The problem with this is that the list of child ids could be huge (thousands) so I’m pretty sure generating a query with ‘WHERE ID IN (thousands of ids…)’ is not the best way to go?
Another option is to find a way of creating a temporary table and inner join it on to the party table. Is this even possible within LLBLGen? I could also create some sort of recursive stored procedure and map the results on to an entity collection but I’d rather avoid this as we’ve already got a hell of a lot to maintain and we’re adding fields to the party table quite often (it’s an evolving system).
I’d be very grateful if anyone could offer any pointers or advice. I'm using LLBLGen Pro v3.1.
Thanks.