Reputation: 6256
Using the example from the documentation:
public class Artist
{
public int ArtistId { get; set; }
public string Name { get; set; }
public IEnumerable<Album> Albums { get; set; }
}
...
var eagerDynamicArtist = db.Artists.FindAllByArtistId(22).WithAlbums().FirstOrDefault();
Console.WriteLine("Artist {0} {1}", eagerDynamicArtist.ArtistId, eagerDynamicArtist.Name);
foreach (var album in eagerDynamicArtist.Albums)
{
Console.WriteLine("\t{0}", album.Title);
}
Problem is, the Albums list is returned null (the generated query is OK).
It works if I change Albums
to:
public IEnumerable<dynamic> Albums { get; set; }
How can I explicitly cast the Albums
table, while defining the Albums
list as IEnumerable<Album>
?
Note: I'm using other tables obviously, but with a similar structure. I'm assuming the "Album" table doesn't magically cast because the POCO class has some more fields (?).
Upvotes: 0
Views: 95
Reputation: 9414
The Albums property should be an IList<Album> rather than IEnumerable<Album>.
Upvotes: 1