Using Linq select list inside list

前端 未结 4 1509
清歌不尽
清歌不尽 2021-02-04 04:08

Using LINQ how to select from a List within a List

public class Model
{
    public string application { get; set; }

    public List users { get; se         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 04:44

    list.Where(m => m.application == "applicationName" && 
               m.users.Any(u => u.surname=="surname"));
    

    if you want to filter users as TimSchmelter commented, you can use

    list.Where(m => m.application == "applicationName")
        .Select(m => new Model
        {
            application = m.application,
            users = m.users.Where(u => u.surname=="surname").ToList()
        });
    

提交回复
热议问题