In my program I have an ADO.NET Entity Data Model with a couple of tables linked to my database. What I want is to make a query to bring me the data of a table and be able to access them as if it were an array.
If for example in the entity there is a table that is called Element that has the columns IdElement, Name, Description and Image, my intention is to make a query on that table to bring me an element with a certain Id, which I do with the following code:
int id = 34;
var entidad = entidad.Elemento.First(x => x.IdElemento == id);
Now I need to be able to access its attributes in the following way:
string nombre = entidad["Nombre"];
string desc = entidad["Descripcion"];
string img = entidad["Imagen"];
To be exact, there would be a variable, "column", that would contain the value of the field that I want to access, so it would be accessed like this:
string valor = entidad[columna];
Any ideas on how to do it?
Thanks.