Contains not Working in LINQ Query

lesponce 176 Reputation points
2022-12-15T15:24:20.683+00:00

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
Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. lesponce 176 Reputation points
    2022-12-15T15:54:56.797+00:00

    I just changed the order of the query statement to myvalues.name.Contains(a.Name) and it worked.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.