从数据库获取所有表,并使用C#,linq查询和实体框架工作遍历每个表 [英] Get all tables from database and loop through each table using C#,linq query and entity frame work

查看:397
本文介绍了从数据库获取所有表,并使用C#,linq查询和实体框架工作遍历每个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有12个表(不包括查找表)的sql server 2012数据库.我正在使用实体框架并尝试查询.我可以查询表格:

I have sql server 2012 database with 12 tables (excluding look up tables). i am using entity frame work and trying to query. 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;


以上适用于1表,但我需要为所有12表做.有没有办法在循环中做到这一点?


above works for 1 table but i need to do it for all the 12 tables. Is there a way to do it in loop

推荐答案

是的,如果您的其他表具有将它们链接在一起的键,则可以这样做.否则,您需要单独阅读它们.您需要解释为什么要执行此操作以及要实现的目标.就目前而言,这根本没有任何意义.

您意识到必须定义包含组合数据的自己的类型吗?您无法从一个表中读取数据并将其存储为另一表中的类型,EF都是强类型的.当然,您可以使用var创建匿名类型.
Yes, if your other tables have keys that link them together, you can do it. Otherwise, you need to read them separately. You need to explain why you want to do this, and what you''re trying to achieve. As it stands, it makes no sense at all.

You realise that you''ll have to define your own type that contains the combined data ? You can''t read the data from one table and store it in a type from another table, EF is all strongly typed. You can use var to create an anonymous type, of course.


这篇关于从数据库获取所有表,并使用C#,linq查询和实体框架工作遍历每个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆