tags:

views:

84

answers:

2

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 generic list of Party objects, such as List, how can I write a LINQ query against the list that will return all of the PartyRelationship objects that have a relationship to a specific PartyId based on the RelatedPartyId? The LINQ query would need to evaluate the RelatedPartyId of all relationships defined for a Party and compare that against a specific PartyId that I am searching for. When a match is found, I would want that specific PartyRelationship object return in the result. BTW, more than one match can occur.

Can anyone provide some insight into how I could do this?

Any help would be appreciated.

Thanks

+3  A: 

Do you mean:

    var query = from party in parties // the list
                where party.RelationShips != null // overkill???
                from related in party.RelationShips
                where related.RelatedPartyId == id
                select related;
Marc Gravell
A: 

Thanks for your help.

Whoiskb
This was unfairly downvoted (fixed) - at the time, Whoiskb did not have the necessary 50 points to add a comment.
Marc Gravell