Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I'm writing a LINQ to SQL statement, and I'm after the standard syntax for a normal inner join with an ON clause in C#.

How do you represent the following in LINQ to SQL:

select DealerContact.*

from Dealer 

inner join DealerContact on Dealer.DealerID = DealerContact.DealerID

1 Answer

0 votes
by (40.7k points)

You can use in this way:

from t1 in db.Table1

join t2 in db.Table2 on t1.field equals t2.field

select new { t1.field2, t2.field3}

Update

Since you are looking for the contacts, this might be more appropriate:

var dealercontacts = from contact in DealerContact

                     join dealer in Dealer on contact.DealerId equals dealer.ID

                     select contact;

Related questions

+1 vote
1 answer
0 votes
1 answer
+3 votes
1 answer
asked Jul 3, 2019 in SQL by Tech4ever (20.3k points)
+2 votes
1 answer

Browse Categories

...