How to query a nested list using a lambda expression

前端 未结 2 797
庸人自扰
庸人自扰 2021-02-04 01:53

In my repository implementation I can run the following query using a lambda expression:

public IList GetUsersFromCountry(string)
{
    return _UserR         


        
相关标签:
2条回答
  • 2021-02-04 02:31

    This might work (untested)...

    var clubs = ClubRepository.Where(c=>c.MemberShips.Any(m=>m.User.Age > 45));
    
    0 讨论(0)
  • 2021-02-04 02:38

    Here's one way to do it:

    var clubs = clubRepository
        .SelectMany(c => c.Memberships, (c, m) => new { c, m })
        .Where(x => x.m.User.Age > 45)
        .Select(x => x.c);
    
    0 讨论(0)
提交回复
热议问题