简体   繁体   English

从数据库获取所有表,并使用C#,Linq查询和Entity Framework遍历每个表

[英]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.

相关问题 使用实体框架从具有条件的关系表中查询 c# - Query from relational tables with conditions using Entity Framework c# 如何使用linq和C#中的实体框架从另一个表中获取对象中的项目列表? - how to get a list of item in object from another table using linq and entity framework in C#? C#对于每个循环,使用数据库实体 - C# For Each Loop, using database entity LINQ 查询使用 C# 中的实体框架获取单列和单行值而不使用 Where - LINQ query Using Entity Framework in C# to get Single Column & Single Row Value Without using Where Foreach标记可遍历c#对象并使用Entity Framework插入数据库 - Foreach tag to loop through c# object and insert to database using Entity Framework 如何使用linq C#使用实体框架获取两个表合并记录? - how to get two table combine record using entity framework with linq c#? 是否可以使用实体框架从 C# 中的几个表中获得加入 SQL 查询的结果? - Is it possible to get result from joined SQL query from several tables in C# with Entity Framework? C# Firebase 数据库循环遍历所有顶级元素并获取每个元素的所有 json - C# Firebase Database loop through all top level elements and get all json for each element C# 实体框架和 Linq 查询 - C# Entity Framework and Linq query 查询Linq到Sql Entity Framework C# - Query Linq to Sql Entity Framework c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM