Using LINQ, how can I get the column names of a table? C# 3.0, 3.5 framework
var query = from x in DataBase.Table_Name
select x.Column_Name;
I stumbled upon this question looking for the same thing and didn't see a really good answer here. This is what I came up with. Just throw it into LINQPad under C# expression mode.
from t in typeof(UserQuery).GetProperties()
where t.Name == "Customers"
from c in t.GetValue(this,null).GetType().GetGenericArguments()[0].GetFields()
select c.Name
Modify as you see fit.
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;
The below code will worked from returns all the column names of the table
var columnnames = from t in typeof(table_name).GetProperties() select t.Name
sp_help 'TableName'
An option for a LinqPad SQL window to ms sql server