Linq查询从table1中选择id在哪里(从table2中选择table2内部联接table3 = table3其中table3 = id)

时间:2019-12-04 13:14:53

标签: linq tsql core

在我的代码中使用ASP.CORE上下文的新功能,我希望使用ASP.CORE Con​​text转换此T-SQL语句

    SELECT ID, SchemeCode, Name 
    FROM   Scheme SM                
    WHERE 
        SM.ParentID = 1             
    AND sm.[ID] 
                IN (SELECT dd.[Scheme_id]
                    FROM  dbo.[Employer_Detail] dd 
                    INNER JOIN dbo.[Employer] er ON dd.Employer_id = er.Employer_id
                    WHERE er.Employer_Parent_id = 123)

1 个答案:

答案 0 :(得分:0)

已解决

var npSchemes = from scheme in _context.Schemes
    join ded in _context.DeductionCodes on scheme.Id equals
    ded.SchemeId
    join er in _context.Employers on ded.EmployerId equals
    er.Id
    where scheme.ParentId == parentId && er.ParentId == employerId
    select new {scheme.Id, scheme.Code, scheme.Name};
    var result = npSchemes.GroupBy(sm => sm.Id).Select(grp =>
    grp.First()).ToList();