LINQ:获取表的详细信息 [英] LINQ: Get Table details
本文介绍了LINQ:获取表的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用LINQPad,我想知道表的架构细节。
I'm using LINQPad and I would like to know schema details of a table.
我知道我做的使用SQL的:
I know that I do it using SQL:
SELECT column_name,*
FROM information_schema.columns
WHERE table_name = '{table_name}'
ORDER BY ordinal_position
我怎样才能做到这一点使用LINQ?
How can I do this using LINQ?
推荐答案
LINQ to SQL的上下文有一个映射
属性,您可以使用这样的事情。就像你所提供可能看起来像这样一个查询:
LINQ to SQL contexts have a Mapping
property that you can use for this sort of thing. A query like the one you provided might look something like this:
from t in context.Mapping.GetTables()
where t.TableName == "[table_name]"
from c in t.RowType.DataMembers
orderby c.Ordinal
select new {columnName = c.Name, columnInfo = c}
请参阅<一href="http://stackoverflow.com/questions/4380834/how-can-i-walk-the-relationships-between-tables-in-linq/4381910#4381910">this回答更多的细节。
这篇关于LINQ:获取表的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文