List of all objects generated from the data model

How can I get a list of all Entities types generated from the Entity data model (* .edmx)?

I already have the table names from the database and the model instance (.edmx).

I want to have an instance of the type of all data objects.

Suppose my database has two tables: EmployeeType

then the model will generate 2 classes and display the data. I am looking for a way to get a list (of type). In this case, the list of results will be considered an instance of Employee.GetType () and EmployeeType.getType ()

Thanks!

(VS2010, VB.NET, EF4)

+4
source share
2 answers

One way to do this:

((EdmItemCollection)ctx .MetadataWorkspace .GetItemCollection(DataSpace.CSpace)) .GetItems<EntityType>() 

I have not tried it before, but you can even get items directly from the workspace:

 ctx.MetadataWorkspace.GetItems<EntityType>(DataSpace.CSpace) 

If you are using a DbContext, you can get an ObjectContext as follows:

 ((IObjectContextAdapter)ctx).ObjectContext 
+2
source
 using (AdventureWorksEntities context = new AdventureWorksEntities()) { IQueryable<Product> productsQuery = from product in context.Products select product; Console.WriteLine("Product Names:"); foreach (var prod in productsQuery) { Console.WriteLine(prod.Name); } } 

Object Queries - MSDN

0
source

All Articles