LEFT OUTER JOIN
问题描述:
我知道有吨对这个职位,但他们都对我不明白什么是左,右以及任何LEFT OUTER JOIN
我有2只列出了具体的问题:左对。我需要选择左侧不合适的所有元素。
List<T> left = GetLeft();
List<T> right = GetRight();
IEnumerable result = // Have no idea
我该怎么做?
答
这听起来不像一个连接在所有...这听起来像:
var result = left.Except(right);
答
这里是一个解决方案,我发现。
找到所有的客户没有购买:
SQL:
Select c.Name from Customers c Left Outer Join Purchases p on c.customerid=p.customerid where p.price is null
LINQ:
from c in Customers join p in Purchases on c.customerid=p.customerid into custPurchases from cp in custPurchases.DefaultIfEmpty() where cp==null select new { cc.Name }
看起来完蛋了,我太习惯SQL – Dani 2011-04-13 15:43:58