Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linq中连接多个表时,如何从查询返回值?_Linq_Linq To Entities - Fatal编程技术网

在Linq中连接多个表时,如何从查询返回值?

在Linq中连接多个表时,如何从查询返回值?,linq,linq-to-entities,Linq,Linq To Entities,我有一个Linq查询,它将表连接在一起,并将两个表内部连接在一起。有时,当表为空时,查询会出错。我试图做的是,即使其他表是空的,我也尝试从表中获取一个值 提前感谢。您需要进行左键连接 假设客户和订单表之间存在左联接 var query = from customer in dc.Customers from order in dc.Orders .Where(o => customer.CustomerId == o.CustomerId)

我有一个Linq查询,它将表连接在一起,并将两个表内部连接在一起。有时,当表为空时,查询会出错。我试图做的是,即使其他表是空的,我也尝试从表中获取一个值

提前感谢。

您需要进行左键连接 假设客户和订单表之间存在左联接

var query =
    from customer in dc.Customers
    from order
    in dc.Orders
         .Where(o => customer.CustomerId == o.CustomerId)
         .DefaultIfEmpty()
    select new { Customer = customer, Order = order }
另请参阅下面的链接