以下两个查询在速度上有区别吗?在这两个查询中,我都返回了自定义对象。
第一个查询使用 IQueryable ,而另一个查询使用 IEnumerable
public IEnumerable<InvoiceViewModel> GetDraftInvoices(int companyId, string locale, InvoiceStatus invoStatus, Guid refNo)
{
IQueryable<InvoiceViewModel> draftInvoces = (from invo in _context.Invoice
join cus in _context.Customer
on invo.CustomerId equals cus.CustomerId
where invo.CompanyId == companyId
&& invo.InvoiceStatus == invoStatus.ToString()
&& (refNo == Guid.Empty || cus.RefNo == refNo)
select new InvoiceViewModel
{
StringInvoNumber = invo.InvoiceNumber.ToString().PadLeft((int)NumberPadd.TicketNumber, '0'),
CustomerName = cus.CustomerName,
ContractName = !string.IsNullOrEmpty(invo.ContractName) ? invo.ContractName : "N/A"
});
return draftInvoces;
}
public IEnumerable<InvoiceViewModel> GetDraftInvoices(int companyId, string locale, InvoiceStatus invoStatus, Guid refNo)
{
IEnumerable<InvoiceViewModel> draftInvoces = (from invo in _context.Invoice
join cus in _context.Customer
on invo.CustomerId equals cus.CustomerId
where invo.CompanyId == companyId
&& invo.InvoiceStatus == invoStatus.ToString()
&& (refNo == Guid.Empty || cus.RefNo == refNo)
select new InvoiceViewModel
{
StringInvoNumber = invo.InvoiceNumber.ToString().PadLeft((int)NumberPadd.TicketNumber, '0'),
CustomerName = cus.CustomerName,
ContractName = !string.IsNullOrEmpty(invo.ContractName) ? invo.ContractName : "N/A"
});
return draftInvoces;
}