Search code examples
vb.netentity-framework-4entity-relationship

Load related entity's from jump table


I have a jump table to relate the Customers and the contact, I want to load all contacts by a customer name. What is the best way to do that?

   Dim Q = From Cust In EnData.Customers Where Cust.CustomerID = ID Select Cust
            ContactRow = Q.FirstOrDefault.CustomerToContacts.??? here I'm stock...

table layout


Solution

  • Try this...

    var customerContacts = EnData.CustomerToContact
                               .Where(c => c.Customer.CustName.Equals(custName))
                               .Select(c => c.Contact);
    

    This should return an IQueryable<Contact> containing all of the contacts for the customer with the provided custName. You'll have to convert it to VB as this is in C#, although I assume that should be rather straight forward.