第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Linq到SQL左轉外部聯(lián)接

Linq到SQL左轉外部聯(lián)接

慕村225694 2019-07-22 19:09:42
Linq到SQL左轉外部聯(lián)接此查詢是否等效于LEFT OUTER加入?//assuming that I have a parameter named 'invoiceId' of type intfrom c in SupportCaseslet invoice = c.Invoices.FirstOrDefault(i=> i.Id == invoiceId)where (invoiceId == 0 || invoice != null)    select new {       Id = c.Id       , InvoiceId = invoice == null ? 0 : invoice.Id}
查看完整描述

3 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

不完全是因為左-外連接中的每個“左”行將匹配0-n“右”行(在第二個表中),其中-因為您的行只匹配0-1。要做左外連接,您需要SelectManyDefaultIfEmpty,例如:

var query = from c in db.Customers
            join o in db.Orders
               on c.CustomerID equals o.CustomerID into sr            from x in sr.DefaultIfEmpty()
            select new {
               CustomerID= c.CustomerID, ContactName=c.ContactName,
               OrderID = x.OrderID == null ? -1 : x.OrderID};

(或者通過擴展方法)


查看完整回答
反對 回復 2019-07-22
?
繁花如伊

TA貢獻2012條經(jīng)驗 獲得超12個贊

您不需要Into語句:

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 } 
    //Order will be null if the left join is null

是的,上面的查詢確實創(chuàng)建了一個左外部聯(lián)接。

鏈接到處理多個左聯(lián)接的類似問題:Linq到SQL:多個左外部聯(lián)接


查看完整回答
反對 回復 2019-07-22
  • 3 回答
  • 0 關注
  • 401 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號