Lambda expression with AND operator in lambda expression
.net, c#, entity-framework, lambda, linq
Solution
You can't use `ToString()` in LINQ method, but you can try this:
string selectedItem = listBox1.SelectedItem.ToString();
CUSTOMER customer = db.CUSTOMERs.First(p => (p.CUSTOMERID == idValoare) && (p.ADRESA.Equals(selectedItem)));
I hope that helps you. Please feedback.
Problem
I get an error ( Object reference not set to an instance of an object ) when i try to do the database operation, i can't seem to find what's wrong, must be something from this `p.ADRESA.Equals(listBox1.SelectedItem.ToString()` because without it the code works but i need two conditions, please help ``` Int16 idValoare =Convert.ToInt16 (comboBoxIDValoare.SelectedItem.ToString()); if (selectedTabel.Equals("CUSTOMER")) { if (selectedColoana.Equals("ADRESA")) { CUSTOMER customer = db.CUSTOMERs.First(p => (p.CUSTOMERID == idValoare) && (p.ADRESA.Equals(listBox1.SelectedItem.ToString()))); customer.ADRESA = textBoxValoare.Text; db.SaveChanges(); } } ```