如何使用与实体框架具有相同模式的多个表

问题描述:




不要问为什么,但我有多个具有相同架构的表(现有数据库,我无法更改)。然后我想在comboBox或listBox中选择表格,然后获取数据。

Table01

Table02

Table03



Hi
Don't ask why but I have multiple tables with the same schema (existing database, I can't change this). Then I want select in comboBox or listBox the table and then get data.
Table01
Table02
Table03

var result = context.Table01.Select(p => p);





我可以以某种方式将Table01替换为Table02以不进行多次查询取决于组合框选择吗?



Can I somehow replace Table01 with Table02 to not make multiple queries depends on comboBox selection?

如果不是不可能的话,你所尝试的可能并不容易。因为对于实体框架,2个不同的实体(以及2个不同的表)是2个不同的东西,不可替换。为什么你甚至想要更换它。只是为了编写更少的代码?
What you are trying might not be easy if not impossible. Because for entity framework, 2 different entities(and so 2 different tables) are 2 different things and are not replaceable. And why do you even want to replace it. Just to write less code ?


如果你有70个数据库,在这个数据库中你将有多个表,你可能也会询问可能性:)



我以前使用简单的命令,阅读器,我可以在查询中更改表或数据库。但是由于数据库创建者的愚蠢,我现在有很多工作要做。如果我想在linq查询中更改某些内容,我必须在所有查询中更改此内容。
IF you will have 70 databases, and inside this databases you will have multiple tables you probably ask also about possibility :)

I used to use simple command, reader and I could change table or database in query. But right now because of stupidity of database creator I have a lot of work. If I want to change something in linq query I have to change this in all queries.