[英]linq - Left join with select max and check if record is not null
I have 3 tables: 我有3张桌子:
I need to select customers join with users, left join with payments. 我需要选择与用户一起加入的客户,与付款一起离开的顾客。 Sometimes I need to check if max record from payment is not null.
有时我需要检查付款的最大记录是否不为空。
I wrote this but it crashes: 我写了这个,但是崩溃了:
I get parameter to this function - byCard 我得到此函数的参数-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.