使用LINQ从动态创建的表中读取

时间:2021-07-05 15:25:33

We create tables in runtime. They have the same schema layout as tables that exist in our DBML but with an alternate name. We want to set the table names in runtime in our use of Linq to Sql.

我们在运行时创建表。它们具有与我们的DBML中存在但具有备用名称的表相同的模式布局。我们想在运行时使用Linq to Sql设置表名。

Using wrapper classes on the Metadata as outlined in https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=4233721&SiteID=1 works great for the updates, deletes and inserts.

使用https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=4233721&SiteID=1中概述的元数据上的包装类非常适合更新,删除和插入。

Does anyone know how we can get the read of the alternate table to work?

有谁知道如何让备用表的读取工作?

2 个解决方案

#1


1  

You need to use an external mapping file. Populate the xml with the names of your table at runtime. This over-rides the attribute based mapping.

您需要使用外部映射文件。在运行时使用表的名称填充xml。这会覆盖基于属性的映射。

#2


0  

You need to new up your LINQ expression at run-time via System.Linq.Expressions

您需要通过System.Linq.Expressions在运行时新建LINQ表达式

#1


1  

You need to use an external mapping file. Populate the xml with the names of your table at runtime. This over-rides the attribute based mapping.

您需要使用外部映射文件。在运行时使用表的名称填充xml。这会覆盖基于属性的映射。

#2


0  

You need to new up your LINQ expression at run-time via System.Linq.Expressions

您需要通过System.Linq.Expressions在运行时新建LINQ表达式