LINQ:获取表详细信息

inq*_*one 9 .net c# linq linq-to-sql

我正在使用LINQPad,我想知道表的架构细节.

我知道我是用SQL做的:

SELECT column_name,* 
FROM information_schema.columns
WHERE table_name = '{table_name}'
ORDER BY ordinal_position
Run Code Online (Sandbox Code Playgroud)

我怎么能用LINQ做到这一点?

Str*_*ior 6

LINQ to SQL上下文具有Mapping可用于此类事物的属性.像您提供的查询可能看起来像这样:

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}
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅此答案.