daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var count = GetEntitySetCount(myObjectContext.MetadataWorkspace);
  2.  
  3.    public static int GetEntitySetCount(MetadataWorkspace workspace)
  4.    {
  5.         var count = 0;
  6.  
  7.         // Get a collection of the entity containers from storage space.
  8.         var containers = workspace.GetItems<EntityContainer>(DataSpace.SSpace);
  9.  
  10.         foreach(var container in containers)
  11.         {
  12.             //Console.WriteLine("EntityContainer Name: {0} ",
  13.             //                  container.Name);
  14.  
  15.             foreach(var baseSet in container.BaseEntitySets)
  16.             {
  17.                 if(baseSet is EntitySet)
  18.                 {
  19.                     count++;
  20.  
  21.                     //Console.WriteLine(
  22.                     //    "  EntitySet Name: {0} , EntityType Name: {1} ",
  23.                     //    baseSet.Name, baseSet.ElementType.FullName);
  24.                 }
  25.             }
  26.         }
  27.  
  28.         return count;
  29.     }
  30.    
  31. myObjectContext.ExecuteStoreQuery<int>(
  32.                 "SELECT COUNT(*) from information_schema.tables WHERE table_type = 'base table'");
  33.    
  34. var connection = ((EntityConnection)myObjectContext.Connection).StoreConnection as SqlConnection;
  35.  
  36. var cmd = new SqlCommand("SELECT COUNT(*) from information_schema.tables WHERE table_type = 'base table'", connection);
  37.  
  38. connection.Open();
  39.  
  40. var count = (int)cmd.ExecuteScalar();
  41.  
  42. connection.Close();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top