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.
The error is stating that you should use FirstOrDefault()
instead of First()
Not sure what the question is
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).FirstOrDefault().Product.ProductsName.Name
}).ToList();
dataGridViekryar.DataSource = a;
Of course this will throw an error if there isn't any items from your query (NullReferenceException)