This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am querying to get a list of parent entities that have an eager load to a list of child enties per parent. Pretty standard stuff to combat N+1 and the I can see 2 select statements being fired in a single sql query, 1st to get the parents and 2nd to get the children. The problem I am seeing is that each child collection in the parent is showing 0 items in the collection. Getting 1 parent item by id works. The child collection is eager loaded correctly. Surely eager loading works against sets of parents? I am attempting this using release 4.0.1688.21487 Thanks, Jim |
|
|
Yes - eager loading should be working consistently for a set of parents as it does for a single parent. Are you using a named aggregate at all to control eager loading?
|
|
|
Hi Jeremy, I have resolved it but I wonder if you can elaborate on why. I have a good idea but would like it confirmed. The issue is down to how we pass a select lambda into a paging function. We have a linq query that has had the correct with aggregate statement applied to it. This query is then passed to a PagedList constructor as below:
The paged list constructor is:
Now the problem is here: Select(x => x.AsResource()) This for some reason doesn't allow the query to actually build an aggregated set of queries. To fix it I created a AsPagedList extension method that calls a different PagedList constructor which accepts an IEnumerable and not IQueryable.:
The call to this changed to:
And as the extension class executes the query on the ToList before the Select and asResource mapping occurs then the aggregate queries are issued. Does this make sense? Thanks, Jim |
|
|
If I am understanding you correctly the difference between those two queries is that the second one is using a projection via the .Select() call. When we perform a projection eager loads are ignored. In the first example because you are forcing an enumeration via .ToList() before the .Select() call we treat this as a standard entity query and eager loads are triggered. If you need the eager loads to be triggered you will need to structure your queries to perform enumeration prior to using a Select call. Let me know if there is anything still fuzzy about how this works :)
|
|
|
Thanks Jeremy and yes this all makes sense. |
|
|
ometimes we want to use eager loading as:-
So how do we go about this, the domain model for this example looks like this:-
view plainprint?
public class Movie : Entity public class Actor : Entity |
|
|
You will want to use the [EagerLoad] attribute on your backing field (or by toggling the Eager Load option for the entity property from the Designer). Have a read through http://www.mindscapehq.com/documentation/lightspeed/Performance-and-Tuning/Controlling-How-Entities-Load for a bit more detail on how to go about doing this and let us know if you have any other questions on this :)
|
|