从表中检索列名 [英] Retrieve Column Names From Table

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

问题描述

有没有一种方法可以使用实体获取特定表的列名?我的意思是,我可以使用
通过SQL获得它

Is there a way to obtain the column names of a particular table using entity? What I mean is that I can obtain it via SQL with

CODE
SELECT Column_Name FROM Information_Schema.Columns WHERE TABLE_Name = 'TableName'


我试图通过反射获取信息,但是它返回列名称以及关联名称.

我正在做的是用字段名称填充一个组合框.

提供C#代码.谢谢.

REgards,
Prathap.


I attempted to obtain the information via Reflection but it returns the column names, as well as the association names.

What I am doing is populating a combo box with the field names.

Provide C# code.Thank you.

REgards,
Prathap.

推荐答案

看,谷歌
Look, what google found for you:
IEnumerable<fieldlist> properties = from p in typeof(T).GetProperties()
                                    where (from a in p.GetCustomAttributes(false)
                                    where a is EdmScalarPropertyAttribute   
                                    select true).FirstOrDefault();



您可以根据 p 对其进行进一步过滤.我建议您深入研究
属性 [ ^ ]属性



You can further filter it based on p. I suggest you dig deeper on the Attributes[^] property


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

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