April 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

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

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

Essentially, the code follows the guidelines of the first routine to walk through the BDC schema, beginning with the LobSystem and the instances contained in the "NamedLobSystemInstancesDictionary". Inside the Instances collection, there is a check to search for the correct Entity ("AnimalsEntity" in the example), and using an empty filter, the results of the BDC are loaded in the Instance Enumerator. The example uses an empty filter to put on view all the content of the database, but it is possible to define a subset of the results in the filter.

Each item in the Instance Enumerator is read using a 'while' statement, and the content is downloaded in a DataTable (don't forget to use a directive to System.Data). By looping through the columns of the DataTable, it is possible read the value of the row and print it onto the screen. Finally, a new row can be read and printed.



Click here for a larger image.

Figure 3: BDC output printed on the screen

Modifying the Schema

As mentioned earlier, the NameSpaces' MetadataModel and Runtime are read-only and especially suitable to read data in a swift, cached way. To modify a BDC schema, it is necessary to use the Administration NameSpace.

The subsequent routine alters the query of the BDC's schema in the example:

static void ChangeQuery()
{
   myAdmin.LobSystemInstanceCollection mySysInstances =
      myAdmin.ApplicationRegistry.Instance.LobSystemInstances;

   foreach (myAdmin.LobSystemInstance mySysInstance in mySysInstances)
   {
      if (mySysInstance.Name == "MyZooInstance")
      {
         myAdmin.EntityCollection myEntities =
            mySysInstance.LobSystem.Entities;
         foreach (myAdmin.Entity oneEntity in myEntities)
         {
            if (oneEntity.Name == "AnimalsEntity")
            {
               myAdmin.MethodCollection myMethods = oneEntity.Methods;
               foreach (myAdmin.Method oneMethod in myMethods)
               {
                  if (oneMethod.Name == "AnimalsMethod")
                  {
                     string myQuery =
                        "SELECT Animals.AnimalID AS AnimalID,
                                Animals.AnimalSurename + '
                                (' + Animals.AnimalFamilyname + ')'
                         AS Animal, " +
                            "DangerousLevels.DangerousLevelDescription
                         AS DangerousLevel
                         FROM Animals
                         INNER JOIN DangerousLevels
                         ON " + "Animals.AnimalDangerousLevel =
                            DangerousLevels.DangerousLevelID
                         WHERE (Animals.AnimalID " + ">".Normalize() +
                            "=@GenMinAnimalID) and (Animals.AnimalID "
                            + "<".Normalize() + "=@GenMaxAnimalID)
                         ORDER BY DangerousLevel";
                     oneMethod.Properties.Remove("RdbCommandText");
                     oneMethod.Properties.Add("RdbCommandText",
                                              myQuery);
                  }
               }
            }
         }
      }
   }
}

Be aware that the directive to the NameSpace "Microsoft.Office.Server.ApplicationRegistry.Administration" has been connected to the variable "myAdmin" because the NameSpaces Administration and MetadataModel have classes with the same name, and in this way the compiler can identify and separate them without problem.

In the same way as with the other routines, use a couple of loops to navigate the Instances, Entities, and Methods to find the correct values ("MyZooInstance", "AnimalsEntity", and "AnimalsMethod"). Finally, a new query is defined: in the example, the "ORDER BY" has been changed from "AnimalID" to "DangerousLevel", to present the results in a different order.



Click here for a larger image.

Figure 4: BDC results before and after programmatically changing the query





Page 3 of 4



Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel