November 27, 2014
Hot Topics:

Business Data Catalog in Microsoft Office SharePoint Server 2007 and the Object Model

  • October 17, 2007
  • By Gustavo Velez
  • Send Email »
  • More Articles »

The next routine loops through the complete schema, showing the relevant information:

static void GetProperties()
{
   NamedLobSystemInstanceDictionary mySysInstances =
      ApplicationRegistry.GetLobSystemInstances();

   foreach (string mySysInstanceName in mySysInstances.Keys)
   {
      LobSystemInstance myLobSystemInstance =
         mySysInstances[mySysInstanceName];
      LobSystem myLobSystem = myLobSystemInstance.GetLobSystem();
      Console.WriteLine("SystemLOB  - " + myLobSystem.Name);
      Console.WriteLine("* Instance - " + mySysInstanceName);

      NamedEntityDictionary myEntities =
         myLobSystemInstance.GetEntities();
      foreach (string myEntity in myEntities.Keys)
      {
         Entity oneEntity =
            myLobSystemInstance.GetEntities()[myEntity];
         Console.WriteLine("** Entity - " + oneEntity.Name);

         NamedMethodDictionary myMethods = oneEntity.GetMethods();
         foreach (string myMethod in myMethods.Keys)
         {
            Method oneMethod = oneEntity.GetMethods()[myMethod];
            Console.WriteLine("*** Method - " + oneMethod.Name);

            NamedPropertyDictionary myProperties =
               oneMethod.GetProperties();
            Console.WriteLine("\n\r" + "**** Query - " +
               myProperties["RdbCommandText"].ToString().Trim());
         }
      }
   }
}

The first element of a BDC schema identifies the schema with a specific name. The "NamedLobSystemInstanceDictionary" contains the collection of schemas in the Catalog, and the "GetLobSystemInstances" method fills the variable with the schemas present in the system.

By looping through the collection, it is possible to find all the relevant information about the LOB's Instances and systems, and the routine prints the name of the LOB system and the name of the Instance.

Each LOB System Instance contains one or more Entities. The "NamedEntityDictionary" contains the collection and the "GetEntities" method loads the variable with the Entities in the Instance. Continue using a 'foreach' statement to examine each Entity and make an instance of them to display and use its properties (the name of the entity will be printed in the example).

In a similar way, each Entity embraces one or more Methods. These are contained in the "NamedMethodDictionary" collection and can be filled using the method "GetMethods" of the entity. Looping through the different methods, an instance of the method is made and one of the properties printed (its name). Apart from properties reached from the Object Model, the Method object has a "NamedPropertyDictionary" bag with its properties; in the example, an instance of the collection is made, filled with the "GetProperties" method, and one of the properties is printed on the screen; namely, the query used in the schema to retrieve the data from the database.



Click here for a larger image.

Figure 2: Routine results for reading the BDC schema

Reading the Output

It also is possible to execute a Business Data Catalog and read the output using the MetadataModel and Runtime NameSpaces. The next routine shows the results from the example's BDC:

static void GetData()
{
   NamedLobSystemDictionary myLobSysDictionary =
      ApplicationRegistry.GetLobSystems();

   foreach (LobSystem system in myLobSysDictionary.Values)
   {
      NamedLobSystemInstanceDictionary mySysInstances =
         system.GetLobSystemInstances();

      foreach (LobSystemInstance oneInstance in mySysInstances.Values)
      {
         Entity myEntity =
            oneInstance.GetEntities()["AnimalsEntity"];
         FilterCollection myFilterCollection =
            myEntity.GetFinderFilters();
         IEntityInstanceEnumerator myEntityInstanceEnumerator =
            myEntity.FindFiltered(myFilterCollection, oneInstance);

         while (myEntityInstanceEnumerator.MoveNext())
         {
            DataTable myZooDataTable =
               (myEntityInstanceEnumerator.Current as
                DbEntityInstance).EntityAsDataTable;
            foreach (DataColumn oneAnimal in
                     myZooDataTable.Rows[0].Table.Columns)
            {
               Console.Write(myZooDataTable.Rows[0][oneAnimal] + "\t");
            }
            Console.WriteLine()
         }
      }
   }
}




Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel