I'm struggling with a conversion of SQL query to LINQ.
Here is the SQL:
SELECT dbo.ORGANIZATION.ORGANIZATION_ID,
dbo.ORGANIZATION.ORGANIZATION_NAME,
dbo.PWR_ORGANIZATION_DIRECTORY.DIRECTORY_IDENTIFIER,
dbo.DETAIL_REQUIREMENT.DETAIL_ID,
dbo.DETAIL_REQUIREMENT.DETAIL_IDENTIFIER,
dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.DIRECTORY_ATTRIBUTE,
dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.ATTRIBUTE_VALIDATION,
dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.ATTRIBUTE_TRANSFORMATION,
dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.DETAIL_ACCESS
FROM dbo.ORGANIZATION INNER JOIN
dbo.DETAIL_REQUIREMENT ON dbo.ORGANIZATION.ORGANIZATION_ID = dbo.DETAIL_REQUIREMENT.ORGANIZATION_ID INNER JOIN
dbo.PWR_ORGANIZATION_DIRECTORY INNER JOIN
dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING ON dbo.PWR_ORGANIZATION_DIRECTORY.ORGANIZATION_ID = dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.ORGANIZATION_ID AND
dbo.PWR_ORGANIZATION_DIRECTORY.DIRECTORY_TYPE_ID = dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.DIRECTORY_TYPE_ID AND
dbo.PWR_ORGANIZATION_DIRECTORY.DIRECTORY_ID = dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.DIRECTORY_ID ON
dbo.DETAIL_REQUIREMENT.DETAIL_ID = dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.DETAIL_ID AND
dbo.ORGANIZATION.ORGANIZATION_ID = dbo.PWR_ORGANIZATION_DIRECTORY_MAPPING.ORGANIZATION_ID
WHERE dbo.ORGANIZATION.ORGANIZATION_ID = 0 AND
dbo.PWR_ORGANIZATION_DIRECTORY.DIRECTORY_ID = 1 AND
dbo.PWR_ORGANIZATION_DIRECTORY.DIRECTORY_TYPE_ID = 1
And this is how I started but got confused when there were two and three joins between tables:
var megaFetch = from org in context.Organizations
join detReq in context.DetailRequirements on org.OrganizationId equals detReq.OrganizationId
join detMap in context.OrganizationDirectoryMappings on org.OrganizationId equals detMap.OrganizationId &&
Can someone guide me here?
Thanks.
If you need to join a tables in more than one column, create anonymous types with both sides having same number of fields. It should be like;
new {col1 = x.col1, col2 = x.col2, ...} equals new { col1 = y.col1, col2 = y.col2, ...}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.