使用where子句将linq值(int)与int List进行比较

时间:2014-01-03 08:06:01

标签: linq list contains

我有一个linq查询,它连接几个表并将值返回到一个对象中。查询工作正常,直到我添加了一个where子句.Aftre where子句,我的查询返回null。

以下是代码:

List<Int32> resourceSupervisorIdList = new List<Int32>();

resourceSupervisorIdList.Add(searchCriteriaTimesheet.ResourceId);

foreach (resource res in allSubordinateResources)
{
    if (!resourceSupervisorIdList.Contains(res.id_resource))
        resourceSupervisorIdList.Add(res.id_resource);
}

using (tapEntities te = new tapEntities())
{
    var timesheetAll = (from tsh in te.timesheet_header
                        join rs in te.resources on tsh.id_resource equals rs.id_resource
                        join tsd in te.timesheet_detail on tsh.id_timesheet equals                   tsd.id_timesheet
                        where (resourceSupervisorIdList.Contains(rs.id_resource_supervisor))
                        select new TimesheetHeaderDetailsItem()
                        {
                            OrganizationId = rs.id_organization,
                            ProjectId = tsd.id_project,
                            StartDate = tsh.dte_period_start,
                            EndDate = tsh.dte_period_end,
                            ApprovedDate = tsh.dte_approved,
                            RejectedDate = tsh.dte_rejected,
                            SubmittedDate = tsh.dte_submitted,

                          });

    if (timesheetAll == null || timesheetAll.Count() == 0)
    {
        return result;
    }
}

现在,在添加where子句后,代码将运行到if条件。表中有匹配的记录,但我仍然无法获得任何记录。

rs.id_resource_supervisor

在mysql db中是int类型。

0 个答案:

没有答案