SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
it is also Lookup field column and it is point to another list named LeaveType – Stark Jun 11 '12 at 9:14
up vote 0 down vote accepted

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


share|improve this answer
can you please give me the suggestion to correct it? – Stark Jun 11 '12 at 9:23
Updated my answer – Gennady Vanin Геннадий Ванин Jun 11 '12 at 9:30
but DepartmentId is the lookup column linked with the field Title....and Title is a renamed to DepartmentName – Stark Jun 11 '12 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 – Gennady Vanin Геннадий Ванин Jun 11 '12 at 11:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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