Click here to Skip to main content
15,891,730 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
SQL
select D.CommonName,D.CoursesFK,D.DepartmentDetailsFK,
D.ID,D.LegalName,C.LegalName as Courses,DD.CourseYear as DepartmentID  from Departments D 
 join Courses C on C.ID=D.CoursesFK
 left outer join DepartmentDetails DD on DD.ID=D.DepartmentDetailsFK;

How to convert this MsSQL query to linq..?
Posted
Updated 16-Sep-12 19:36pm
v2

Try something like this:
C#
from dept in Departments
JOIN course in courses ON dept.CoursesFK equals course.ID
JOIN deptDetail in DepartmentDetails ON dept.DepartmentDetailsFK equals deptDetail.ID
select NEW
{
    dept.CommonName,
    dept.CoursesFK,
    dept.DepartmentDetailsFK,
    dept.ID,
    dept.LegalName,
    course.LegalName as Courses,
    deptDetail.Courseyear as DepartmentID
}
 
Share this answer
 
Comments
suganyass 17-Sep-12 1:45am    
Thanks for your reply. Tried that query. But not works. There is some problem in using join.
Prasad_Kulkarni 17-Sep-12 1:45am    
What is it??
suganyass 17-Sep-12 1:52am    
I got result, but result collection repeated twice.
Prasad_Kulkarni 17-Sep-12 1:53am    
Add where condition, for your expected o/p.
suganyass 17-Sep-12 1:59am    
I need all rows from departments.
go through below site and download Linquer. It converts SQL query to Linq
http://www.sqltolinq.com/[^]
 
Share this answer
 
try this:
C#
From D In Departments Join C in Courses ON C.ID equals D.CoursesFK Group Join DD in DepartmentDetails on DD.ID equals D.DepartmentDetailsFK
select NEW {    D.CommonName,    D.CoursesFK,    D.DepartmentDetailsFK,    D.ID,    D.LegalName,
    C.LegalName as Courses,    DD.Courseyear as DepartmentID
}

See below Link.
It Will HelpFul For you.
Link 1[^]
Link 2[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900