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've set up a project where I have the entities: Photo and Tag and I've set up a through association called PhotoTags - which I've made into an explicit through association. I want to take advantage of you Aggregates so I can use eager loading on certain queries, and have given the one to many association between Photo and PhotoTags a Collection Aggregate called "PhotoWithPhotoTags" and the one to many association between Tag and PhotoTags a Backreference Aggregate called "PhotoTagsWithTag" I then use the following to find all photos with the tag having an Id of 3: IQueryable<Photo> photos = uow.Photos.WithAggregate("PhotosWithPhotTags").WithAggregate("PhotoWithPhotoTags").WithAggregate("PhotoTagsWithTag").Where(y => y.PhotoTags.Where(z => z.Tag.Id == 3).Any()); The SQL generated is:
SELECT t0.Id AS [t0.Id], t0.Filename AS [t0.Filename] FROM Photo t0 INNER JOIN (SELECT t0.Id, t0.PhotoId, t0.TagId FROM PhotoTags t0 INNER JOIN Tag t1 ON t0.TagId = t1.Id WHERE t0.TagId = 3 ) q1 ON t0.Id = q1.Id
So the eager loading is working as it's all in the one query, but no results are returned as the join in the SQL in on the Id columns of Photo and PhotoTag when in fact what I want is a join on Photo.Id = PhotoTag.PhotoId - so the last line of the generated SQL should be t0.Id = q1.PhotoId What am I doing wrong? Thanks, Andy |
|
|
Hi Andy, The incorrect join was a bug, and we have resolved this today and it will be available in the next nightly build. A couple of other things that are likely of use here :) - Only one .WithAggregate will be valid for the query because the underlying LightSpeed engine supports a single aggregate name per query. You can however use the same aggregate name across entities to cascade for the same result. - Also your query could probably be optimized to .Any(z => z.Tag.Id == 3) rather than .Where(z => z.Tag.Id == 3).Any().
Jeremy |
|