假设我有一个数据库名为 MyDatabase的
其中有两个表 - MYTABLE1
和 MyTable2
。使用与实体框架4.x和.NET 4中的code第一种方法,我已经产生了命名上下文 MyDatabaseContext
包含 MyTable1s
和 MyTable2s
。
Suppose I have a database named MyDatabase
which has two tables - MyTable1
and MyTable2
. Using the Code First approach with Entity Framework 4.x and .NET 4, I have generated a context named MyDatabaseContext
which contains MyTable1s
and MyTable2s
.
通常情况下,表的访问像 MyDatabaseContext.Table1s<指挥GT;
。在我的数据库中许多表共用一对夫妇共同的领域(如CreatedOn,ModifiedOn)的。我想就能够动态地替换表名,所以我可以执行对任何表相同的查询。
Normally, tables are accessed like MyDatabaseContext.Table1s.<Command>
. In my database many tables share a couple of common fields (e.g. CreatedOn, ModifiedOn). I would like to to be able to dynamically substitute a table name so I can execute the same query against any table.
我真正想要的(和它似乎并没有用)是一样的东西 MyDatabaseContext [ContextTableName]&LT;指挥GT;
What I really want (and which does not seem to be available) is something like MyDatabaseContext[ContextTableName].<Command>.
没有人有任何想法,如果这样的功能存在在查询时动态地选择一个表。
Does anyone have any idea if such functionality exists to dynamically select a table at query time.
我有同样的问题,与表被打造为每天像这样:TableName_2014_06_06
i had same issue with tables that were build for each day like: TableName_2014_06_06
在最后我只是回到基础知识和使用的SqlConnection .. 我建议你做同样的
In the end i just went back to basics and used SqlConnection .. I suggest that you do the same