How do you get the column names from a db?
Currently, I'm interacting with the db through linq-sql using an ado.net entity model. I've searched through StackOverflow and I got a few helpful posts but nothing I've tried has worked.
Like take this post:
How do I return the column names of a LINQ entity
I tried the responses from Conrad Frix but they didn't work. I'm not exactly sure what he means by a 'Datacontext' anyway. Is that Entity?
AttributeMappingSource mappping = new System.Data.Linq.Mapping.AttributeMappingSource();
var model = mappping.GetModel(typeof (AdoModelEntities));
var table = model.GetTable(typeof (TableName));
var qFields= from fields in table.RowType.DataMembers
where fields.IsPersistent == true
select fields;
foreach (var field in qFields)
Console.WriteLine(field.Name);
This doesn't work because table is null