Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ: Get Table Column Names

Tags:

Using LINQ, how can I get the column names of a table? C# 3.0, 3.5 framework

like image 942
Lennie De Villiers Avatar asked Nov 26 '09 11:11

Lennie De Villiers


People also ask

How to get column name from DataTable in c# using LINQ?

Try this (LINQ method syntax): string[] columnNames = dt. Columns. Cast<DataColumn>() .


1 Answers

Maybe It is too late but, I solved this problem by this code

var db = new DataContex(); var columnNames = db.Mapping.MappingSource                       .GetModel(typeof(DataContex))                       .GetMetaType(typeof(_tablename))                       .DataMembers; 
like image 59
erkan Avatar answered Sep 18 '22 18:09

erkan