代码之家  ›  专栏  ›  技术社区  ›  bugfixr

Linq to Entities:左连接以获取连接中未找到的项目

  •  0
  • bugfixr  · 技术社区  · 16 年前

    TimeData table 
    - userID 
    - taskID 
    - hours
    


    ApprovedTasks table (the one that should contain nulls)
    - taskID 
    - userID 
    

    SQL查询看起来像这样:

    select * from TimeData td 
    left join ApprovedTasks at
     on at.taskID = td.taskID and at.userID = td.userID
    where at.taskID is null
    

    有什么方法可以使用LINQ to Entity查询来实现这一点吗?

    短暂性脑缺血发作

    1 回复  |  直到 16 年前
        1
  •  3
  •   Community Mohan Dere    8 年前

    Disjoint Union in LINQ

    var approvedTaks = from at in ApprovedTasks.Except(
                                            from at2 in ApprovedTasks
                                            where at2.userID == userId and at2.taskID==taskId
                                            select at2)
                        where at.userID == userId and at.taskID==taskId
                        select at;
    

    推荐文章