Nguyễn Ngọc Duy
Nguyễn Ngọc Duy

Reputation: 1260

Retrieve table columns via table names in Entity Framework

How do i retrieve a list of table columns in the database via table name in Entity Framework Database First?

Upvotes: 0

Views: 133

Answers (1)

Stefan Taseski
Stefan Taseski

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

Related Questions