我正在尝试创建ApplicationUsers的列表,以查找与正确发票对应的客户。我在下面尝试了以下方法,但是得到了NullReferenceException:
System.NullReferenceException:对象引用未设置为对象的实例。
我的控制器中的代码:
private string FindCustomerForReservation(List<Invoice> invoices, List<ApplicationUser> customers, Reservation currentReservation)
{
string customername;
Invoice correspInvoice = invoices.Find(f => f.Id == currentReservation.Invoicenumber);
ApplicationUser customer = customers.Find(k => k.Id == correspInvoice.CustomerId);
customername = customer.UserName;
return customername;
}
所以我假设列表为空或为空。那是正确的还是其他?
我该如何解决?