I have 2 tables:
- Customers
- ConnectedCustomers
Connected customers table holds 2 foreign keys to Customers table and basically it looks like this:
What I'm wondering here is how can I return both customers from related table?
I've tried something like this (NOT ALLOWED):
query = from c in _context.Customers join cc in _context.ConnectedCustomers
on c.customerId equals cc.customer1_id OR c.Id equals cc.customer2.id
select c;
And this is not allowed... so I googled little bit and I've found people are ussually working with anonymous types in this cases, so I've tried something like this:
This also did not work because I included twice c.customerId and it says anonymous type cannot have multiple properties with the same name
.
query = from c in _context.Customers join cc in _context.ConnectedCustomers
on new { c.customerId, c.customerId } equals new { cc.customer1_id, cc.customer2 }
select c;
So I've removed one of c.customerId
from anonymous type and it looked like this:
query = from c in _context.Customers join cc in _context.ConnectedCustomers
on new { c.customerId } equals new { cc.customer1_id, cc.customer2 }
select c;
But than I've received error on join which said: The type of one of the expressions in the join clausule is incorrect...
Thanks guys !
Cheers