0

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

1 Answer 1

3

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'
Sign up to request clarification or add additional context in comments.

1 Comment

I prefer ToList() instead of ToArray(), but that is a totally valid answer anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.