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