Quote:
But I can't understand, if you're going to the extent of using projections (presumably for some minor performance gain) then why bother with it, if you need the whole object anyway?
:)
You hit the right spot.
I use projections for performance gain, and a very big performance gain.
We have a program where you can choose whatever columns you want to view in a datagrid. And those columns can be chosed whatever you can trace in the object graph, having that you only go only via one-to-one relationships (i.e. the "one" side of the "one-to-many" relationship).
Say, we are viewing a collectin of Teaching Group objects. Then in the grid we can choose any properties from the object graph, for example:
group object properties
Group.TeachingProgramme properties
Group.GroupLeader properties
Group.GroupLeader.Company properties
etc.
The problem is that if we have very big object graph, the it gets extremely slow to load all object graph.
We did tests withs 15k objects (which is not much), and we had around 15 seconds delay to load all those objects, and then display in the grid.
After making projections, so that it instead of loading 15k object graphs, we select only the properties we display in the grid. The time went down to 3-5 seconds. That is, the performance gain was 3 to 5 times. That's alot.
So that's why we use projections.
Now why do i want to select the object. Basically, the idea is this:
When we had objects in the grid, we did not have to query for them when we pressed edit or delete buttons. We already had the objects, so no need to loag again.
Now, as we have only properties in the grid, we load an additional column Id, so that we could know which object we want to edit or delete. Thus, before invoking edit or delete command, we have to query for the object.
Now, the biggest problem is that the programming paradigm shifted - the grid now contains not the objects, but the properties and ID of the object. If it would be possible to select both properties and the object (only the root object, without any relationships), the way we programming would not have to change - The grid would always return the object it is showing, and not the Id of that object.
Now, i do not say this is the best my though ever in my life :D
It's just brainstorming. As far as i think, the performance would not suffer alot for selecting one object without any relationships, but it would help as have our API more consistent.
Just random thoughts :)