2014-03-26 26 views
2

我有一個用戶名單附加到包括客戶端的應用程序。我期望通過Linq過濾應用程序和客戶端的用戶列表,並且正在旋轉。乾淨的LINQ實現過濾由孫子女名單

理想情況下我會使用其中Application.Name ==「榜樣」,同時也是在ClientApp.Id ==單個語句1.

這是我在哪裏迄今,但我有一些關於嵌套的內部大腦問題。任何幫助表示讚賞

var users2 = users.Where(x => x.App.Select(y => y.Name).Contains("example")); 

public class User 
{ 
    public string FirstName { get; set; } 
    public List<Application> App { get; set; } 
} 
public class Application 
{ 
    public string Name { get; set; } 
    public List<ClientApp> Client { get; set; } 
} 
public class ClientApp 
{ 
    public string Id { get; set; } 
} 

回答

5

您可以使用嵌套調用Enumerable.Any過濾這樣的:

var filtered = users.Where(u => 
        u.App.Any(
         a => a.Name == "example" 
         && a.Client.Any(c => c.Id == 1))); 
+0

由於大部分裏德和@TimS。 –