简体   繁体   中英

Retrieve table columns via table names in Entity Framework

如何通过Entity Framework Database First中的表名检索数据库中表列的列表?

If you need to get the names of the columns in C# code, then it would be something like this:

var names = typeof(TableName).GetProperties()
                    .Select(property => property.Name)
                    .ToArray();

If you need the columns names in the database via query then something like this:

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'TableName'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM