Home > Backend Development > C++ > How to Perform an Inner Join in LINQ to SQL?

How to Perform an Inner Join in LINQ to SQL?

Barbara Streisand
Release: 2025-01-28 07:26:10
Original
284 people have browsed it

How to Perform an Inner Join in LINQ to SQL?

linq to sql connect grammar

The internal connection in linq to SQL combines two tables according to the public key value. This is represented by the Join operator with an ON clause.

Example:

Suppose we have a database, which contains two tables: dealer and dealerContact. To perform internal connections between these two tables, we will use the following Linq to SQL statements:

This statement retrieves all records that match the dealerid in the dealerContact table in the Dealer table.

var dealercontacts = from contact in DealerContact
                     join dealer in Dealer on contact.DealerId equals dealer.ID
                     select contact;
Copy after login
<法> grammar:

The conventional syntax connected in the inner connection in linq to SQL is:

Among them: <<>

T1 and T2 are tables to be connected
from t1 in db.Table1
join t2 in db.Table2 on t1.field equals t2.field
select new { t1.field2, t2.field3}
Copy after login

Field is the public key value

    Field2 and Field3 are the fields to be retrieved from the connection table

The above is the detailed content of How to Perform an Inner Join in LINQ to SQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template