LINQ: INNER JOIN

Converting from INNER JOIN to LINQ

SQL:

SELECT * FROM dbo.MAIN_TABLE

INNER JOIN dbo.JOIN_TABLE ON

dbo.MAIN_TABLE.ROLEID = dbo.JOIN_TABLE.ID

AND dbo.MAIN_TABLE.EMPLID = ‘020’

Here’s the LINQ equivalent:

Dim _returnClass = From mainTable In _myAuthEntities.MAIN_TABLE

                  Where mainTable.EMPLID = ‘020’

                  Join joinTable In _myAuthEntities.JOIN_TABLE

                  On mainTable.ROLEID Equals joinTable.ID

                  Select New ReturnClass With {.ID = joinTable.ID,

                                .SiteID = joinTable.SITEID,

                                .Descp = joinTable.DESCP,

                                .EmplID = mainTable.EMPLID,

                                .CreateDT = joinTable.CREATE_DATE,

                                .RoleCode = joinTable.ROLECODE}

Return _returnClass.ToList()

Again, i returned it using a new type ReturnClass. Nothing fancy, just fields and properties.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s