c# - Linq to sql - 左外连接

标签 c# linq-to-sql left-join

我有如下三张表没有关联

  1. 客户
  2. 银行
  3. 国家

一些客户他们没有银行详细信息,所以我需要获取所有的客户信息,谁有银行,谁没有银行,以及国家信息

我知道这是“左外连接”方法。它如何在 Linq to sql 中使用

vb.net代码请

最佳答案

enter image description here

var query = 
    from order in dc.Orders
    from vendor 
    in dc.Vendors
         .Where(v => v.Id == order.VendorId)
         .DefaultIfEmpty()
    from status 
    in dc.Status
         .Where(s => s.Id == order.StatusId)
         .DefaultIfEmpty()
    select new { Order = order, Vendor = vendor, Status = status } 
    //Vendor and Status properties will be null if the left join is null

LEFT OUTER JOIN in LINQ To SQL

关于c# - Linq to sql - 左外连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3633444/

相关文章:

C# - 全局程序对象

Mysql SUM 输出错误

sql - 从LEFT OUTER JOIN删除重复项

c# - 如何在 ExcelInterop 中查找第一个和最后一个单元格以及 C# 中的图形范围

c# - 未生成的 Azure Functions C# 输入绑定(bind)是 function.json

c# - PowerModeChanged 延迟触发

c# - 如何在 Linq to SQL 中使用 distinct 和 group by

asp.net-mvc - Linq to SQL 替换相关实体

sql-server - 有没有一种方法可以防止死锁(所发生的情况是一个发生并且一个受害)

mysql - 连接两个日期之间的 MAX id