是否可能在實體框架核心(或7)中加載表中沒有相關記錄的所有記錄表?EF.Core加載在其他表中沒有相關記錄的所有記錄
在我的情況下,我有一個Customers表和一個Contracts表。客戶可以有0到N份合同。在這個特殊用例中,我想查詢所有沒有合同的客戶。
**Customer Table:**
CustomerId | Name
---------- | ----------
1 | Apple
2 | Google
3 | Microsoft
**Contracts Table:**
| ContractId | CustomerId | StartDate | EndDate |
| ---------: | ---------: | ---------- | ---------- |
| 1 | 2 | 01-01-2016 | 01-01-2018 |
| 2 | 3 | 01-01-2016 | 01-01-2018 |
在這種情況下,我希望查詢只返回一個包含Apple客戶的對象。
在SQL我會做這樣的事情:
select cust.CustomerId, cust.Name
from dbo.Customers as cust
left outer join dbo.Contracts as contr
on cust.CustomerId = contr.CustomerId
where contr.ContractId is null;
我如何翻譯這一個EF查詢?
謝謝你,所以簡單和工程就像一個魅力 –