2

How to order by StartDate and UserLikeProduct? I need to sort by StartDate but show by UserLikeProduct first.

public IEnumerable<Check> GetHomeCeeck() { return this.Query() .Where(c => c.IsPublish && c.IsHomepageProduct) .OrderBy(c => c.StartDate) .Take(30) .ToList(); } 
0

2 Answers 2

2

If I understand you correctly, you want to order by one and then the other?

use .ThenBy(lambda) after the .OrderBy(lambda).

If this is not what you meant then let me know and I'll remove this answer

.OrderBy(c => c.StartDate).ThenBy(c => c.Like) 
Sign up to request clarification or add additional context in comments.

2 Comments

Incorrect syntax near the keyword 'asc'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'asc'. Source Error: Line 25: { Line 26: Line 27: return this.Query().Where(c => c.IsPublish && c.IsHomepageProduct).OrderBy(c=>c.StartDate).ThenBy(c=>c.UserLikeProduct).Take(30).ToList(); Line 28: } Line 29:
@smartboy What data type is 'UserLikeProduct'? Is it an IComparable? Although that may not matter since this is trying to generate SQL
1

See this question: Multiple Order By with LINQ

You need to OrderBy() and then ThenBy().

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.