How do i retrieve a list of table columns in the database via table name in Entity Framework Database First?
1 Answer
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'
1 Comment
mkdavor
I prefer ToList() instead of ToArray(), but that is a totally valid answer anyways.