0

I got two lists, a lists of facebooks, and a list of users.

The facebook object gets only a property, id, like:

public class EFacebook
{
    public string id { get; set; }
}

The second list is a list of users, but the object is more complex, each user gets a nullable list of providers inside, one of these providers can be a facebook one, and each provider gets a id, like:

public class EUser
{
    public List<EProvider> EProviders { get; set; }
}

public class EProvider
{
    public enum EnumProviderType
    {
        Facebook = 2,
        Twitter = 3
    }

    public EnumProviderType ProviderType { get; set; }
    public string Id { get; set; }
}

I need to filter the facebook list based on the users providers, getting two children lists, users that are facebooks and users that are not facebooks. I'm trying something like:

var query1 =
    from i in users
    where i.EProviders.Any(j => j.ProviderType == EProvider.EnumProviderType.Facebook)
    select i.EProviders;

var query =
    from i in facebooks
    where i.id.Equals(???)
    select i;
4

2 回答 2

0

建立在你已经拥有的基础上,这可能会奏效

var query2 =
    from i in users
    where i.EProviders.All(j => j.ProviderType != EProvider.EnumProviderType.Facebook)
    select i.EProviders;
于 2012-04-11T18:36:00.507 回答
0

从带有投影 ( .Select) 的完整列表中选择,类似于:

users.Select( u => new { User: u, 
                         IsFacebookUser: facebook.Any( f => f.Id == u.Providers
                                                    .Single( p => p.providerType == facebookProvider).id) }

以上是象征性的,我没有机会编译。有了这个,如果有 facebook 帐户,您将获得所有用 bool 标记的用户的列表。

于 2012-04-11T18:36:12.107 回答