I'm trying to order by an attribute of a related object. Just an example, this is the situation. I have this two classes:
public class Publication
{
public int Id { get; set; }
public string Name { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public int PublicationId { get; set; }
[ForeignKey("PublicationId")]
public Publication Publication { get; set; }
public int Category { get;set; }
}
Now I need to get all the Publications with Product's Category = 1 and ordered by Publication Id desc:
IQueryable<Publication> query = db.Publications.Where("Products.Any(Category = 1)");
List<Publication> list = query.OrderBy("Id desc").ToList();
This is working great! But... How can I order Publications by Product's category (desc or asc) using Dynamic Linq?