I want to retrieve data from the database in different tables by relation, but I get an error that I don't know how to handle.
int customer_id = int.Parse(this.comboBoxnamecustomer.SelectedValue.ToString());
a = (from c in db.Invoices where c.CustomerID == customer_id select new {
customerName = c.Customer.Name,
ProductName = c.InvoiceItems
.Where(x => x.InvoiceId == c.InvoiceId)
.First().Product.ProductsName.Name
}).ToList();
Unhandled Exception: System.NotSupportedException: The method 'First' can only be used as a final query operation. Consider using the method 'FirstOrDefault' in this instance instead.
The problem is with the .First()
method, but if I remove it I can't pass to another table.