Question

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 (?).

Was it helpful?

Solution

The Albums property should be an IList<Album> rather than IEnumerable<Album>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top