Question

Inside the AdventureWorks database we have Individuals, Contacts and Customers. These 3 tables are related. My goal is to get the FirstName, LastName and Email up on the Customers when I call them.

Is there a way to resolve this with mappings?

Thanks in advance. Kyor

EDIT: Structure: Structure of the table

Was it helpful?

Solution

I can think of two ways:

1) Using Include()

 var customers = context.Customer.Include("Individual.Contact");

Then you can access the properties by: customers.First().Individual.Contact.FirstName;

2) Projecting to a new Type

  var customers = from c in context.Customer
                  select new NewCustomerType
                  {
                    Customer = c,
                    FirstName = c.Individual.Contact.FirstName,
                    LastName = .Individual.Contact.LastName,
                    .
                    .
                    .
                  };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top