views:

37

answers:

1

Hi,

I have a Entity Framework design with a few tables that define a "graph". So there can be a large chain of relationships between objects in the few tables via concept of parent/child relationships.

What is a performance way to 'tree-walking' through my Entity Framework data?

That is I assume I wouldn't want to load the full set of all NODES and RELATIONSHIPS from the database for the purpose of walking the tree, where the end result may only be identifying leaf nodes? Or would this be OK with the way lazy loading may work at the column/parameter level?

Else how could I load just the skeleton of the objects and then when needing to refer to any attributes have them lazy load then?

The other alternative I guess is to just keep hitting the database as the "walk the tree" routine occurs. Perhaps is better to start out simple this way and then test performance, but then the point of this question would be if performance was an issue, which way would then one go.

EDIT: I was thinking here of lazy loading somehow at the attribute level - i.e. for each NODE object I load as I expand the graph out only loading the ID and Foreign Keys, i.e. enough to build the graph of nodes in memory. Then if I actually want to get info from a particular node in memory the attributes info could be got in a "lazy" approach. Know if this is possible? Not sure whether this would be better overall anyway?

+1  A: 

I think Lazy loading is what you're looking for. http://thedatafarm.com/blog/data-access/a-look-at-lazy-loading-in-ef4/

Doobi
that seems to be the normal lazy loading at the entity level no? - I was thinking here of lazy loading somehow at the attribute level - i.e. for each NODE object I load as I expand the graph out only loading the ID and Foreign Keys, i.e. enough to build the graph of nodes in memory. Then if I actually want to get info from a particular node in memory the attributes info could be got in a "lazy" approach. Know if this is possible? Not sure whether this would be better overall anyway?
Greg
Hmm, perhaps a way to do it would be to create 2 entity models, where one is just a node tree (enitities of just keys) and when you find want you want you load by id in the full model?
Doobi
oh, I hadn't realized/thought of doing this
Greg