views:

386

answers:

1

Hello,

I have two tables, in a many-to-many relationship, with a junction table, as follows:

Member       MemberGroup        Group
=========    ============       =======
PK | ID      PK | ID            PK | ID
   | Name       | Member           | Name
                | Group
                | MemberSince

I need to add all the members of a specific group to a list box. The group is selected from a data bound combo box. I was looking to do something like this:

listbox1.ItemsSource = DataModel.Members.Where(u=>u.Group == mygroup);

However, the Member entity only contains the MemberGroup entries.... not the actual groups.

What is the best way to do this?

By the way, .NET Framework 3.5, WPF, Entity Framework, C#, SQL Server Compact Edition (2008)

+1  A: 

Found the solution.

public partial class Group
{
    public ObjectQuery<Member> Members
    {
        get
        {
            return (from j in DataModel.MemberGroup
                    where j.Group.ID == this.ID
                    select j.Member) as ObjectQuery<Member>;
        }
    }
}
Mike Christiansen