I am new to sharepoint and i am using Linq to Sharepoint in my project. I have two Lists in TestSite. Details are as below


DepartmentName Single line of text
ManagerId Person or Group
IsActive Choice


EmployeeId Person or Group
LeaveDescription Multiple lines of text
ApprovalStatus Choice
FromDate Date and Time
ToDate Date and Time
LeaveTypeId Lookup
DepartmentId Lookup
AppliedDate Date and Time
AssignedTo Person or Group
RejectionReason Multiple lines of text

I am trying to join these two list. By doing some googling on it i have created following Linq query but in the result it is showing Enumeration yielded no results.

the code is as below :

        SPList lstDept = SPContext.Current.Web.Lists["Department"];
        SPList lstLeaveDetails = SPContext.Current.Web.Lists["LeaveDetails"];

        var v = from SPListItem ld in lstLeaveDetails.Items
                join SPListItem dept in lstDept.Items on ld["DepartmentId"] equals dept.Title
                select new
                    Emp = ld.Title,
                    Id = dept.ID

So, can any one tell what i am doing wrong?

  • it is also Lookup field column and it is point to another list named LeaveType
    – Stark
    Jun 11, 2012 at 9:14

1 Answer 1


This join will always have null result set since

ld["DepartmentId"] equals dept.Title

will always result in false because ld["DepartmentId"] will never equal to dept.Title since they are of different types

You must join on fields of the same type
I even do not see in your Department list a field "Title" but I presume it is there as "Single line of text" while "DepartmentId" is int (Number, Number of decimal places: 0)

You should have probably written, as minimum:

ld["DepartmentId"] equals dept.Id  

instead of

ld["DepartmentId"] equals dept.Title   

If the DepartmentId is lookup to field DepartmentName then write:

ld["DepartmentId"] equals dept.DepartmentName


  • can you please give me the suggestion to correct it?
    – Stark
    Jun 11, 2012 at 9:23
  • Updated my answer Jun 11, 2012 at 9:30
  • but DepartmentId is the lookup column linked with the field Title....and Title is a renamed to DepartmentName
    – Stark
    Jun 11, 2012 at 9:32
  • Updated by Update2. You might probably not have Title field after its renaming if you have not created a new one with such name Jun 11, 2012 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.