Hi
I am getting error on below code - Only arguments that can be evaluated on the client are supported for the String.Contains method.
LMSDBDataContext context = new LMSDBDataContext();
List Result = (from t in context.View_Recommendations
where (StudentCollection.Length > 0 ? StudentCollection.Contains(t.StudentID.ToString()) : 1 == 1)
select t).ToList();
Thanks
Naimish MakwanaPosted Apr 25, 2023, 4:29 PM
Try this:
Amit MohantyPosted Apr 26, 2023, 4:27 AM
This error message suggests that the
String.Containsmethod is not supported by the LINQ provider that is being used to translate the query into SQL. This can happen when the LINQ provider cannot translate a method call into the appropriate SQL expression.Ramco RamcoPosted Apr 25, 2023, 4:39 PM
Hi naimish
I get the same error - Only arguments that can be evaluated on the client are supported for the String.Contains method.
Studentcollection is a string data type
Thanks
Ramco RamcoPosted Apr 25, 2023, 4:14 PM
Hi Naimish
In sql it is giving correct result I want only those records of STudent Id below , but according to above query it is returning other than these records also
21,24,272
Thanks
Naimish MakwanaPosted Apr 25, 2023, 4:00 PM
The error message you're seeing suggests that the
String.Containsmethod cannot be used in this context because it can only accept arguments that can be evaluated on the client side.Based on your code, it seems that
StudentCollectionis an array of strings that you are using to filter the results of your LINQ query. However, theContainsmethod cannot be used in this way because it is not supported in a SQL query.One possible solution would be to filter the results using a different method, such as the
Enumerable.Containsmethod from theSystem.Linqnamespace. This method can be used to filter the results after they have been retrieved from the database:Thanks