I have list of objects (List<Seat> CurrentSeatStates). Those objects contain filed named Number. And content of those Number fields is the same as some column names. I am using entity framework. Here is part of my code:
Seats seatsRow = new Seats();
seatsRow = (from seats in Db.Seats where seats.SeanceId == seanceId select seats).First();
seatsRow.A1 = !(from s in CurrentSeatStates where s.Number.Equals("A1") select s.IsEnabled).Single();
seatsRow.A2 = !(from s in CurrentSeatStates where s.Number.Equals("A2") select s.IsEnabled).Single();
seatsRow.A3 = !(from s in CurrentSeatStates where s.Number.Equals("A3") select s.IsEnabled).Single();
...
I would like to use foreach loop here and dynamically compare column name (example seatsRow.A3) and content of field Number. So that I would not have to use hardcoded column name. And if those two equals (column name and content of Number filed) them set value from another field IsEnabled.
Any help here much appreciated!
Try something like that:
Where under columnName you can set changeable column name and under value you set value that you want to set.