0
I’m trying to make a query in the table, which her name will come by the scope of the method, but does not allow me to use Select();
or Where();
System.Type referenceTableType =
System.Type.GetType("MeuProjeto.Model." + typeRequest.ReferenceTable);
object TabelaPraConsulta = Activator.CreateInstance(referenceTableType);
var x= Database.Set(TabelaPraConsulta).Select(qw => qw.id = id); // isso nao é possivel
I don’t really know how to do this, I’ve never used Reflection.
Then I would like to be able to make a query with the table name that comes in typeRequest.Referencetable but I don’t know how
That’s good, and probably not necessary. Almost all use of Reflection is wrong. Without context I can’t help anymore, but in this case the way it is, just don’t do it and it’s all solved.
– Maniero
how could I further detail my problem?
– mateus andrade
Doing like the Ciro :)
– Maniero
That looks like XY problem.
– Alisson
I could not understand very well what and why you want to do this, even more so this way... It would not be the case to use
Generics
instead ofReflection
? Or even a simpletypeof()
– Leandro Angelo
is, in case I wanted to set the table name with her name. do not leave pre defined.
– mateus andrade
I tried to put Database."table name". Where(etc, etc); but it doesn’t work
– mateus andrade
As a string in the case
– mateus andrade
@What did you mean by set the table name with its name. do not leave pre defined?
– Alisson
@Alisson, that’s right, I’m sorry if I explained it wrong
– mateus andrade
Pass the context of why you want to do this because I think by object orientation itself you can get around this kind of thing, using generic class might be a good thing.
– Thiago Araújo