嗨我在linq查询下面但是它很慢......我在做左连接时它很慢但是不能真正判断是否是这种情况。
var lastPayment = (from p in _context.CustomerPayment
group p by p.CustomerId into grps
select new
{ PaymentID = grps.Max(x => x.PaymentId) });
List<CustomerPaymentViewModel> data = await (from cp in _context.CustomerPayment
join lp in lastPayment
on cp.PaymentId equals lp.PaymentID into _l
from lp in _l.DefaultIfEmpty()
orderby cp.PaymentId descending
select new CustomerPaymentViewModel()
{
CustomerName = cp.Customer.CustomerName,
PaymentAmount = ((decimal)cp.Payment.PaymentAmount).ToString("n0"),
PaymentDate = cp.Payment.PaymentDate.ToString("yyyy-MM-dd"),
PaymentID = cp.Payment.PaymentId,
OutstandingAmount = cp.OutstandingAmount == null ? "" : ((decimal)cp.OutstandingAmount).ToString("n0"),
PaymentMethod = cp.Payment.PaymentMethod == null ? "" : cp.Payment.PaymentMethod,
Editable = lp != null ? "1" : "0"
}).ToListAsync();