No data prefetched when a RelationCollection is applied to a PrefetchPath.

Posts   
 
    
badaim
User
Posts: 1
Joined: 18-Mar-2009
# Posted on: 18-Mar-2009 05:53:49   

I'm trying to retrieve a specific FilmArtist and its associated FilmItems that match the PredicationExpression I give it. The PredicateExpression requires a RelationCollection, but when I add a RelationCollection to a PrefetchPath with a relation added the associated FilmItems always comes back empty even though there is data that matches the given search criteria.

The FilmArtist and FilmItem tables are associated by a FilmItemFilmArtist table, which I believe give the FilmArtist and FilmItem tables a many to many relationship. Is there a flag or another Property I need to set on the PrefetchPath to accept a RelationCollection?

LLBL version 1.0.2005.1 Final Code generator configuration: Name: SelfServicing, two class scenario (Full / Safe) Version: 1.0.2005.1.10232005 Template: C# template set for SqlServer(1.0.2005.1)

Table FilmArtist FilmArtistID ArtistName DefaultRoleID ArtworkFileName

Table FilmItemFilmArtist FilmItemFilmArtistID FilmArtistID FilmItemID FilmArtistRoleID

Table MediaItem MediaItemID

Table FilmItem descendant of MediaItem FilmItemID Title

Table PhysicalFile PhysicalFileID MediaItemID CodecID

Relationship between tables FilmArtist and FilmItemFilmArtist linked via FilmArtistID Relationship between tables FilmItem and FilmItemFilmArtist linked via FilmItemID Relationship between tables PhysicalFile and MediaItem linked via MediaItemID. FilmItem is a child of MediaItem.


// Join required for the FilmItem to match the given CodecID
RelationCollection Joins = new RelationCollection();
Joins.Add(FilmItemEntity.Relations.PhysicalFileEntityUsingMediaItemId);

PredicateExpression hiddenFilmsFilter = new PredicateExpression();
hiddenFilmsFilter.AddWithAnd(PhysicalFileFields.CodecID == <GivenCodecID>);

SortExpression filmSort = new SortExpression(new SortClause(FilmItemFields.Title, SortOperator.Ascending));

// PrefetchPath that doesn't like any RelationCollection that is set.
IPrefetchPath pfp = new PrefetchPath((int)EntityType.FilmArtistEntity);
IPrefetchPathElement pfToFilms = pfp.Add(FilmArtistEntity.PrefetchPathFilmItemCollectionViaFilmItemFilmArtist, 0, hiddenFilmsFilter, Joins, filmSort);
pfToFilms.SubPath.Add(FilmItemEntity.PrefetchPathFilmGenreCollectionViaFilmItemFilmGenre);

// Get the FilmArtist and its FilmItems that match the given CodecID
artist = new FilmArtistEntity(ArtistID, pfp);

// This collection always comes back empty when a RelationCollection is added to the PrefetchPath
artist.FilmItemCollectionViaFilmItemFilmArtist
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 18-Mar-2009 06:17:46   

2 things to do.

1- Inspect the generated prefetch query and run it against the database to see whether it returns records or not.

2- Use the latest build of LLBL version 1.0.2005.1, as it seems you are using a very old build.