LINQ to Object Help

I have the following entity structure:

public class Party
{
    public Int32 PartyId { get; set; }
    public List<PartyRelationship> RelationShips { get; set; }
}

public class PartyRelationship
{
    public Int32 PartyId { get; set; }
    public Int32 RelatedPartyId { get; set; }
}

Now, if I create a general list of Party objects, such as List, how can I write a LINQ query to a list that will return all PartyRelationship objects that are related to a specific PartyId based on RelatedPartyId? A LINQ query would have to evaluate the Associated PartyId of all the relationships defined for the Party and compare them with the specific PartyId that I am looking for. When a match is found, I want the specific PartyRelationship object returned as a result. By the way, there may be several coincidences.

Can someone give an idea of โ€‹โ€‹how I can do this?

Any help would be appreciated.

thanks

+3
source share
1

:

    var query = from party in parties // the list
                where party.RelationShips != null // overkill???
                from related in party.RelationShips
                where related.RelatedPartyId == id
                select related;
+3

All Articles