Linq:获取DataContext中所有表的列表 [英] Linq: Get a list of all tables within DataContext

查看:71
本文介绍了Linq:获取DataContext中所有表的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含100多个表的DataContext(从Linq到Sql),是否可以获取所有这些表的列表,并可以说将它们打印到控制台?这可能是一个愚蠢的问题.

I have a DataContext (Linq to Sql) with over 100 tables, is it possible to get a list of all those tables and lets say print them to the console? This might be a silly question.

谢谢.

推荐答案

比上面容易得多,并且不需要反射. Linq to SQL具有Mapping属性,可用于获取所有表的枚举.

It's much easier than above and no reflection required. Linq to SQL has a Mapping property that you can use to get an enumeration of all the tables.

context.Mapping.GetTables();

这篇关于Linq:获取DataContext中所有表的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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