This question is locked. New answers and comments are not allowed.
Now I am doing search page. the requirement is user can input keyword seperated by comma. The system must find content that match in 'or' case for example user input a,b,c... The system should generate SQL like this
SELECT * FROM [Table] WHERE [Keyword] LIKE '%a%' OR [Keyword] LIKE '%b%' OR [Keyword] LIKE '%c%'
so I implemented like this
string[] keywords = searchKeyword.Split(',');
Expression<
Func
<Property, bool>> predicate = PredicateBuilder.False<
Property
>();
foreach ( string temp in keywords)
{
if (string.IsNullOrEmpty(temp))
continue;
string keyword = temp;
predicate = predicate.Or(obj => obj.SearchKeyword.Contains(keyword));
}
query = query.Where(predicate);
The problem is when I try to test it with input a,b,c the SQL will be like this. I have monitored from SQL Server Profiler.
SELECT * FROM [Table] WHERE [Keyword ]LIKE '%a%' OR [Keyword] LIKE '%a%' OR [Keyword] LIKE '%a%'
I have tried to change query from this link http://blogs.telerik.com/blogs/posts/10-04-16/dynamic_filter_expressions_in_an_openaccess_linq_query.aspx because I thought the problem will come from compiled LINQ however the result still wrong.
Could you please suggest me how to fix this issue or let me know the sample or other way to support in this case.
Thank you & Regards,
Visoot Soisang