The probably best way to list out entities is probably like this:
private void PopulateTableNames()
{
List<string> listOfTables= new List<string>();
tabeller.Clear();
var metadata = ((IObjectContextAdapter)db).ObjectContext.MetadataWorkspace;
var tables = metadata.GetItemCollection(DataSpace.SSpace)
.GetItems<EntityContainer>()
.Single()
.BaseEntitySets
.OfType<EntitySet>()
.Where(s => !s.MetadataProperties.Contains("Type")
|| s.MetadataProperties["Type"].ToString() == "Tables");
var PropertiesInTables = tables.Select(s => s.ElementType.Properties).ToList();
foreach (var table in tables)
{
var tableName = table.MetadataProperties.Contains("Table")
&& table.MetadataProperties["Table"].Value != null
? table.MetadataProperties["Table"].Value.ToString()
: table.Name;
var tableSchema = table.MetadataProperties["Schema"].Value.ToString();
listOfTables.Add(tableName);
}
}
Attention should also go to this line in the code sample above:
var PropertiesInTables = tables.Select(s => s.ElementType.Properties).ToList();
This Linq query also gives you the fields (properties) of each table.
[From romiller.com]