I am using entity framework v2.2.3. I am trying to order a sub-entity by using the following code but it did not work.
var result= _databaseContext.Movie.AsNoTracking().Include(p => p.Cast.OrderByDescending(c => c.Birthday)).ToList();
Error:
The Include property lambda expression 'p => {from Cast c in p.Casts orderby [c].Birthday desc select [c]}' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'. For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393.
Entities:
public class Movie
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public List<Cast> Casts { get; set; }
}
public class Cast
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public DateTime Birthday { get; set; }
}
Do you have any idea?