How do you request multiple tables at once with a list of table names as strings?

So, I work in a company where there are several tables with different names, but exactly the same structure (date, time, value). I would like my program (C # or LINQ / LINQPad) to go through these tables and query for a specific row, so I can make sure all of them have been updated properly. Is this doable?

So far I have been thinking about this. Knowing that each table name will give it a different class, I try to generally get the values ​​from the table. I can get the table using the code here

DataContext dc = new DataContext(); var myTable = (ITable)dc.GetType().GetProperty("Table").GetValue(dc, null); 

My problem is that I am trying to get columns from this table using a similar method. However, the error below appears:

 foreach(var e in myTable) { double myValue = (double)e.GetType().GetProperty("Value").GetValue(e, null); } 

So, when I looked at all the properties of e.GetType (), I noticed that it had 2, one of which was Context, so I went there to study. However, the next layer down seems to be a dead end for metadata with no actual data coming out of my loop. Am I even heading in the right direction? Once I get this obstacle, it will be easy for me to make a list and get my results in this way. Any help would be greatly appreciated. Thanks.

+6
source share
1 answer

If you need to query many tables using the primary key (EntityKey in the db context), then the ObjectContext has a method called GetObjectByKey that allows you to get an EntityKey so you only need to build an EntityKey. According to the article

You can create an interface that is common to all tables (entites) that have the same structure and pass your object to the interface, or just use dynamic .

+1
source

Source: https://habr.com/ru/post/1013811/


All Articles