0

下面的指定查询显示编译时错误。它说名称wfmilestoneprojectrel不在右侧的范围内equals。考虑交换equals. 我该如何解决这个问题?
请帮忙...

var test = 
   (from wfmilestonedefinition in _context.WF_MILESTONE_DEFINITION
    join wfmilestoneprojectrel in _context.WF_MILESTONE_PROJECT_REL
        on wfmilestonedefinition.MILESTONE_ID equals wfmilestoneprojectrel.MILESTONE_ID
    join workflowrecord in _context.WORKFLOW_RECORD
        on wfmilestoneprojectrel.PROJECT_ID equals workflowrecord.PROJECT_ID
    join workflowmilestone in _context.WORKFLOW_MILESTONE
        on
        new
            {
                wfmilestoneprojectrel.MILESTONE_PROJECT_REL_ID,
                workflowrecord.WF_ID
            } equals
        new
            {
                MILESTONE_PROJECT_REL_ID = wfmilestoneprojectrel.MILESTONE_PROJECT_REL_ID,
                workflowmilestone.WF_ID
            }
    select workflowmilestone).ToList();

Related Sql query which works well are given below : SELECT dbo.WF_MILESTONE_DEFINITION.MILESTONE_ID, dbo.WF_MILESTONE_DEFINITION.MILESTONE_NAME, dbo.WF_MILESTONE_PROJECT_REL.PROJECT_ID, dbo.WORKFLOW_RECORD.WF_ID, dbo.WORKFLOW_MILESTONE.MILESTONE_E_DATE FROM dbo.WF_MILESTONE_DEFINITION INNER JOIN dbo.WF_MILESTONE_PROJECT_REL ON dbo.WF_MILESTONE_DEFINITION.MILESTONE_ID = dbo.WF_MILESTONE_PROJECT_REL.MILESTONE_ID INNER JOIN dbo.WORKFLOW_RECORD ON dbo.WF_MILESTONE_PROJECT_REL.PROJECT_ID = dbo.WORKFLOW_RECORD.PROJECT_ID INNER JOIN dbo.WORKFLOW_MILESTONE ON dbo.WF_MILESTONE_PROJECT_REL.MILESTONE_PROJECT_REL_ID = dbo.WF_MILESTONE_PROJECT_REL.MILESTONE_PROJECT_REL_ID AND dbo.WORKFLOW_RECORD.WF_ID = dbo.WORKFLOW_MILESTONE.WF_ID

4

1 回答 1

1

查看将在幕后调用的 Join 方法的定义:

Join<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter>, 
                                    IEnumerable<TInner>, 
                                    Expression<Func<TOuter, TKey>>, 
                                    Expression<Func<TInner, TKey>>, 
                                    Expression<Func<TOuter, TInner, TResult>>)

您之所以收到此错误,是因为在您的第二个连接子句变量 wfmilestoneprojectrel 中不可用,因为该委托传递了变量 workflowmilestone(TInner):

    new 
    {
      //here is no varialbe with name wfmilestoneprojectrel
      MILESTONE_PROJECT_REL_ID = wfmilestoneprojectrel.MILESTONE_PROJECT_REL_ID,
      workflowmilestone.WF_ID
    }

为什么不直接写:

join workflowmilestone in _context.WORKFLOW_MILESTONE
    on workflowrecord.WF_ID equals workflowmilestone.WF_ID

也许我误解了什么..

于 2013-07-06T09:30:50.953 回答