1

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

Department

DepartmentName Single line of text
ManagerId Person or Group
IsActive Choice

LeaveDetails

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?

Stark
  • 161
  • 1
  • 1
  • 10

1 Answers1

0

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   

Update2:
If the DepartmentId is lookup to field DepartmentName then write:

ld["DepartmentId"] equals dept.DepartmentName

instead