linq string.contains on field of child object list

后端 未结 1 1701
闹比i
闹比i 2020-12-11 18:37

How can the linq statement here be altered so that it finds the company(s) containing the user with the substring of \"third\"?

At the moment it only works when sear

相关标签:
1条回答
  • 2020-12-11 19:31

    You should call string.Contains on the user.Name:

    companies = companies
        .Where(company => company.Users.Any(user => user.Name.Contains("third")))
        .ToList();
    

    See it working online: ideone

    0 讨论(0)
提交回复
热议问题