Query on table name by Reflection

Asked

Viewed 64 times

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.

  • how could I further detail my problem?

  • Doing like the Ciro :)

  • 1

    That looks like XY problem.

  • 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 of Reflection? Or even a simple typeof()

  • is, in case I wanted to set the table name with her name. do not leave pre defined.

  • I tried to put Database."table name". Where(etc, etc); but it doesn’t work

  • As a string in the case

  • @What did you mean by set the table name with its name. do not leave pre defined?

  • @Alisson, that’s right, I’m sorry if I explained it wrong

  • 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.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.