Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a UI that accepts a few parameters from the Search. The search can have the course name, course category, or learning category parameters. I have to get the results on the basis of what the user tries to search.

I have used multiple IF conditions for the Skip and Take logic and the one that is failing is mentioned below.
C#
If(!string.IsNullOrEmpty(coursename) && coursecategory > 0 && LearningCategory == 0)

 var results = Context.CourseDetails
.where(x => x.CourseName == coursename || EF.Functions.Like(x.CourseName, $"%(coursename.Trim()}%") && x.CourseCategory == categoryId)

I think the above Where clause is skipping the second clause after && and not considering the CourseCategory. My results from the above statement should include the search with the search term and also the CourseCategory ID.

Any help on this would be much appreciated. Thanks!

What I have tried:

I tried to enter the Search Term clause in separate brackets but that is not working.
Posted
Updated 27-Apr-22 19:47pm
v2
Comments
PIEBALDconsult 27-Apr-22 19:46pm    
Use parentheses to make your intent explicit.

1 solution

Look closely at your code:
.where(x => x.CourseName == coursename || EF.Functions.Like(x.CourseName, $"%(coursename.Trim()}%") && x.CourseCategory == categoryId)
Are you sure this bit is right:
$"%(coursename.Trim()}%"
   ^                 ^
   |                 |
That's not string interpolation, but this is:
$"%{coursename.Trim()}%"
   ^                 ^
   |                 |
 
Share this answer
 
Comments
CPallini 28-Apr-22 1:56am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900