[英]linq - Left join with select max and check if record is not null
我有3張桌子:
我需要選擇與用戶一起加入的客戶,與付款一起離開的顧客。 有時我需要檢查付款的最大記錄是否不為空。
我寫了這個,但是崩潰了:
我得到此函數的參數-byCard
from c in _db.Customers
from p in _db.Payments.Where(r => r.CustId == c.ID && r.Success).OrderBy(r => r.PaymentDate).Take(1).DefaultIfEmpty()
join u1 in _db.Users on c.UserID equals u1.Id into us
from use1 in us.DefaultIfEmpty()
&& (byCard == "1" ? p!=null : true)
您不應該使用OrderByDescending代替最大的嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.