2
votes
var date = DateTime.Now.AddMonths(-3);
buyers.OrderBy(x => x.Visits.Where( y => y.VisitStart > date).Count());

In the orderby expression I get Cannot convert lambda expression to type 'string' because it is not a delegate type. What the code is supposed to do is sort my "buyers" by number of "visits" they had in last 3 months.

Buyers is entity that has List of Visits and Visit has DateTime VisitStart

If it makes any difference,buyers is IQueryable<Buyer> and Visits is ICollection<Visit>

1
What is buyers? Visits? and VisitStart? - Sriram Sakthivel
Sorry guys.Just edited - Medo
Are you sure that this code gives you error? - Sergey Berezovskiy
If it makes any difference,buyers is IQueryable and Visits is ICollection,probably does - Medo

1 Answers

1
votes

The actual code was

buyers.OrderBy(x => x.Visits.Where( y => y.VisitStart > date).Count() , sort.Direction);

problem was sort.Direction, but I was stupid and thought that it doesn't matter. Sort is type of GridSortOptions and I was using it to sort some stuff manually.

Sorry about question,I left out the most important part obviously