1

I am maintaining a dictionary of clients that are logged in with _clientList.Add(clientIDGuid, newsfeedClient);

NewsfeedClient class:

public class NewsfeedClient
{
    /// <summary>
    /// Represents Newsfeed's own clientID
    /// </summary>
    public string ClientIDGuid { get; set; }  // also adding the dictionary's ID

    /// <summary>
    /// Represents the logged in client's session ID
    /// </summary>
    public string SessionID { get; set; }
    public string Nickname { get; set; }
    public int ProfileID { get; set; }

    public GeoLocation Location { get; set; }

    public List<MyDB.Models.Buddy> BuddyList { get; set; }

    [ScriptIgnore]
    public DateTime LastResponseTime { get; set; }

    public class GeoLocation
    {
        public float Latitude { get; set; }
        public float Longitude { get; set; }
    }
}

The Buddy object contains a ProfileID property.

I want to get a list of all dictionary clientID's where the matching profileID is in the BuddyList of that new client.

I'm guessing that the Intersect method would come into play, as seen here, but I'm not quite sure how to put this together without creating at least one foreach loop.

-- UPDATE --

The clientID is not == ProfileID these values are different.

4

2 回答 2

1

Try this, assuming I've read your question correctly:

var matches = _clientList
            .Where(c => c.Value.BuddyList.Any(b => b.ProfileID == c.Value.ProfileID))
            .Select(c => c.Key)
            .ToList();
于 2012-04-16T20:23:06.450 回答
1

Assuming, I have your question correct, it should be like so:

var matches = _clientList.ToList()
    .Select(x => x.Key)
    .Intersect(currentNewsFeed.BuddyList.Select(x => x.ProfileId))
    .ToList();
于 2012-04-16T20:24:31.807 回答