Reputation: 1260
How do i retrieve a list of table columns in the database via table name in Entity Framework Database First?
Upvotes: 0
Views: 133
Reputation: 232
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'
Upvotes: 3