I just changed the order of the query statement to myvalues.name.Contains(a.Name) and it worked.
Contains not Working in LINQ Query
lesponce
176
Reputation points
I need to run a LINQ query in my code that include a check if a field is equal to one of the values found in a string. For example "ABC, XYZ"
The string values will come from an object called ObjectModel myvalues. Also, the string values will come from the mention object as myvalues.name
If you can advise me how I can get this work, it will be greatly appreciated. My code goes as follow:
var query =
from a in myData
join b in myData
on a.field equals b.field
where (a.Name != null && a.Name.Contains(myvalues.name) // <-- HERE IS THE ISSUE
select new ViewNames { MyNames = (string)a.Name};
Developer technologies | ASP.NET | ASP.NET Core
4,829 questions
Developer technologies | .NET | Other
Developer technologies | .NET | Other
Microsoft Technologies based on the .NET software framework
4,107 questions
Developer technologies | C#
11,581 questions