2
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>

4
  • What is buyers? Visits? and VisitStart? Commented Feb 14, 2014 at 11:34
  • Sorry guys.Just edited Commented Feb 14, 2014 at 11:39
  • Are you sure that this code gives you error? Commented Feb 14, 2014 at 11:40
  • If it makes any difference,buyers is IQueryable and Visits is ICollection,probably does Commented Feb 14, 2014 at 11:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.