[英]Get all tables from database and loop through each table using C#, Linq query and Entity Framework
I have a SQL Server 2012 database with 12 tables (excluding look up tables). 我有一个包含12个表(不包括查找表)的SQL Server 2012数据库。 I am using Entity Framework and trying to query.
我正在使用Entity Framework并尝试查询。 I am able to query a table
我可以查询表格
ClientEntities dc = new ClientEntities();
var query = from client1 in dc.CLIENTTable
where client1.CLIENT_ID == txtId.Text
select client1;
Above works for 1 table but I need to do it for all the 12 tables. 以上适用于1个表,但我需要对所有12个表都执行此操作。 Is there a way to do it in loop?
有没有一种方法可以循环执行?
you can get a list of table with SqlConnection.GetSchema http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a2953687-ff78-47a6-9071-ceac64728d9a/ 您可以使用SqlConnection.GetSchema获取表的列表http://social.msdn.microsoft.com/Forums/zh-CN/adodotnetentityframework/thread/a2953687-ff78-47a6-9071-ceac64728d9a/
after that iterate this list with your query (which became a subquery) Best regards 之后,使用您的查询(已成为子查询)迭代此列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.