1

我有一个SQL query我在两张桌子上表演的。

这是我的查询

Select a.cSubGroupName,a.cAddedBy,a.dAddedOn,b.cGroupName 
from sys_Log_Account_SubGroup a,sys_Account_Primary_Group b 
where a.cAuthorizedStatus='Pending'  and a.nGroupCode=b.nGroupCode 

我正在尝试使用Lambda expression.

4

1 回答 1

2
var query = tA
    .Where(a => a.cAuthorizedStatus == "Pending")
    .Join(tB, a => a.nGroupCode, b => b.nGroupCode, (a, b) => new 
    { 
        cSubGroupName = a.cSubGroupName, 
        cAddedBy = a.cAddedBy, 
        dAddedOn = a.dAddedOn, 
        cGroupName = b.cGroupName 
    });

或者

var query = tA
    .Join(tB, a => a.nGroupCode, b => b.nGroupCode, (a, b) => new 
    { 
        cSubGroupName = a.cSubGroupName, 
        cAddedBy = a.cAddedBy, 
        dAddedOn = a.dAddedOn, 
        cGroupName = b.cGroupName,
        cAuthorizedStatus = a.cAuthorizedStatus
    })
    .Where(j => j.cAuthorizedStatus == "Pending")
    .Select(j => new
    { 
        cSubGroupName = j.cSubGroupName, 
        cAddedBy = j.cAddedBy, 
        dAddedOn = j.dAddedOn, 
        cGroupName = j.cGroupName
    });

请注意,仅当您想明确排除cAuthorizedStatus返回集中的列时,才需要最后一次选择。

于 2012-07-30T09:15:00.130 回答