[Edit]
Perhaps this can be of use to find the number of objects in Storage space
var count = GetEntitySetCount(myObjectContext.MetadataWorkspace); public static int GetEntitySetCount(MetadataWorkspace workspace) { var count = 0; // Get a collection of the entity containers from storage space. var containers = workspace.GetItems<EntityContainer>(DataSpace.SSpace); foreach(var container in containers) { //Console.WriteLine("EntityContainer Name: {0} ", // container.Name); foreach(var baseSet in container.BaseEntitySets) { if(baseSet is EntitySet) { count++; //Console.WriteLine( // " EntitySet Name: {0} , EntityType Name: {1} ", // baseSet.Name, baseSet.ElementType.FullName); } } } return count; }
To retrieve the number of tables in the database, you can do the following in .Net 4.0
myObjectContext.ExecuteStoreQuery<int>("SELECT COUNT(*) from information_schema.tables WHERE table_type = 'base table'");
Using .Net 3.5
var connection = ((EntityConnection)myObjectContext.Connection).StoreConnection as SqlConnection;var cmd = new SqlCommand("SELECT COUNT(*) from information_schema.tables WHERE table_type = 'base table'", connection);connection.Open();var count = (int)cmd.ExecuteScalar();connection.Close();