DBML

...now browsing by tag

 
 

LINQ query to get all the column names in the DBML tables

Friday, October 31st, 2008

// LINQ query to get all the column names for every Table
var model = new AttributeMappingSource().GetModel(typeof(ReportDBMLClassesDataContext));
int i = 0;
ArrayList lblList = new ArrayList();
foreach (var mt in model.GetTables())
{
i++;
Label lbl = new Label();
lbl.Text = mt.TableName.ToString();
lbl.ID = “lbl” + i;
Panel1.Controls.Add(lbl);
Panel1.Controls.Add(new LiteralControl(“<br>”));
int r = 0;
foreach (var dm in mt.RowType.DataMembers)
{
r++;
Label rlbl = new Label();
rlbl.Text = dm.MappedName.ToString();
rlbl.ID = “rlbl” + i + “” + r;
Panel1.Controls.Add(rlbl);
Panel1.Controls.Add(new LiteralControl(“<br>”));
}
}

Written by Deepak Vasa - Visit Website