1

I'm working with asp.net mvc3.

I have a edmx that was created ADO.NET Entity Data Model. (Data-First)

TestDb.Designer.cs

namespace Test.Web.DataModel
{
    public partial class TestDbContext : ObjectContext
    {
         public ObjectSet<T_Members> T_Members { ... }
         public ObjectSet<T_Documents> T_Documents { ... }
         ....
    }
}

T_Members, T_Documents <-- This property is a table of the database.

I want to get a list of this table.

How to get the list of table name from EDMX?

isnotnull
  • 61
  • 4
  • 10

2 Answers2

1

Answer Myself.

TestDbContext context = new TestDbContext();
var tableList = context.MetadataWorkspace.GetItems<EntityType>(System.Data.Metadata.Edm.DataSpace.CSpace);
foreach (var item in tableList)
{
    item.Name;
}

To be help for people who have the same problem ...

isnotnull
  • 61
  • 4
  • 10
0

I think your 'solution' only works when the table and the entity have the same name. If you would rename your entity to Document (without the prefix) it would fail.

Quote from Microsoft employee:

No, unfortunately it is impossible using the Metadata APIs to get to the tablename for a given entity. This is because the Mapping metadata is not public, so there is no way to go from C-Space to S-Space using the EF's APIs.

Community
  • 1
  • 1
Jowen
  • 5,203
  • 1
  • 43
  • 41
  • 1
    That's an old post. Take a look at the solution on the same page. It works - at least for a simple inheritance hierarchy. And has links to more information on accessing the MetaData API http://stackoverflow.com/a/18964974/150342 – Colin Dec 24 '13 at 09:45