var ActiveSides = from q in Building
select new { q.Id, Side as q.Side1, Length as q.Side1Length, Height as q.Side1Height Area as q.Side1Area, Color as q.Side1Color};
foreach (var ActiveSide in ActiveSides)
{
string SideName = ActiveSide.Side;
int SideLength = ActiveSide.Length;
int SideHeight = ActiveSide.Height;
........
ActiveSide.Area = ActiveSide.Height * ActiveSide.Length;
ActiveSide.Color = Green;
}
(Simplified version of problem):
I have an XML database with multiple similar columns. Given an integer that indicates which side of a building I'm working on, I would like to have both read and write access to the "REAL" columns using generic names something like I have shown. The above code DOES NOT COMPILE because I'm not doing it correctly.
QUESTION: what is the correct approach to do this?
Even better would be something like this where all I need is the correct index value and everything else becomes generic.
string Side = SideNames[index];
string Length = LengthNames[index];
string Height = HeightNames[index];
string Area = AreaNames[index];
var CurrentValues = from q in Building
select new { q.Id, q.Side, q.Length, q.Height, q.Area, q.Color};
foreach (var CurrentItem in CurrentValues)
{
string SideName = CurrentItem.Side;
int SideLength = CurrentItem.Length;
int SideHeight = CurrentItem.Height;
........
CurrentItem.Area = CurrentItem.Height * CurrentItem.Length;
CurrentItem.Color = Green;
}
Summary: What I wanted to do was to build a LINQ query at run time and then execute it. This seems like a very normal thing to do but it seems to be impossible. As a result I did it all the 'hard' way by coding all the different queries I needed and then I choose right one with a tedious sequence of (if/else if) blocks. Oh well, it does work this way.