Databases Reference
In-Depth Information
The GetForeignKeyValues method of the MetaForeignKeyColumn class returns a list values
of the primitive entity properties that form the foreign key of a given row or entity
instance. Using the Products table of the Northwind database as an example, the product
called “ Chai ” has a SupplierID equal to 1 ; calling the GetForeignKeyValues method for
this row returns a list with a single Int32 value (1). The order of values returned by this
method matches the order of column names returned by the ForeignKeyNames property.
public string GetForeignKeyPath(string action, object row);
public string GetForeignKeyPath(string action, object row, string path);
The GetForeignKeyPath methods of the MetaForeignKeyColumn class extract the list of
foreign key values from the specified row by calling the GetForeignKeyValues method and
then pass it to the GetActionPath method of the ParentTable . The action parameter is
typically specified using one of the values defined in the PageAction static class. The row
parameter is an instance of the entity that contains the foreign key. And path can be spec-
ified when additional query parameters need to be specified in the query string.
Similar to the GetActionPath method of the MetaTable class, the GetForeignKeyPath
methods are used when a hyperlink is needed to navigate from a child entity to a parent
entity. This is how the read-only ForeignKey field template generates the URL of its hyper-
link.
public string GetForeignKeyString(object row);
The GetForeignKeyString method calls the GetForeignKeyValues method to obtain
values of the primitive foreign key columns and converts them to a string where individ-
ual values are separated by commas. For the Supplier foreign key of the Product entity,
this would return a single SupplierID value, such as “1” for the “Chai” product.
This method serves as a counterpart for the GetPrimaryKeyString method of the MetaColumn
class discussed earlier. The ForeignKey_Edit field template uses the GetPrimaryKeyString
method to generate values for the drop-down list items representing rows from the parent
table. To select the current value of the foreign key property in the drop-down list, it calls
the GetForeignKeyString method.
public void ExtractForeignKey(IDictionary dictionary, string value);
The ExtractForeignKey method is the opposite of the GetForeignKeyString . It takes a
comma-separated list of foreign key-Edit values and extracts them into a dictionary. Field
templates use this method to implement data-binding logic, extract a current foreign key
value from their web controls, and pass it to a data source control. In particular, if the
“Exotic Liquids” is selected as a supplier for the “Chai” product, the ExtractForeignKey
method will receive a string that contains ID of the supplier - “ 1 ” and add value 1 with
key “ SupplierID ” to the dictionary.
 
Search WWH ::




Custom Search