'How to change table name depends on User in EnityFramework?
I would like to change reference to db table depends on model, which would be send by user. For example: I have 3 types (A,B,C) of devices and 3 tables (tableA, tableB, tableC) for each type of device. User would pick that he would like to show data from tableA. In practise I could do it with if constructions, but It would be like 100-200 tables. I would like to read property from model send by user and then convert it to table name, which would be use in EntityFramework. I tried to use Reflection, but I know that soultion won't work.
string example_string = ModelSendByUser.Property;
var Example = myEntityObject.GetType().GetProperty(example_string)?.GetValue(myEntityObject, null);
var ExampleList = myEntityObject.Example.Where(...).ToList();
How to make refenrece to table, which depends on model property sent by User.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|