MetaForeignKeyAssociation
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
The MetaForeignKeyAssociation class represents a foreign key association in the Telerik Data Access metadata model. It derives from the MetaAssociation class. The MetaForeignKeyAssociation class describes one-to-many associations between two classes and gives the following information:
- Constraint - gets the MetaConstraint applied to the current association. If no constraint is applied, null is returned.
- HasDiscriminatorColumn - gets whether the association requires a discriminator column. If the corresponding end in the association is represented by a type stored in a table that is polymorphic (contains multiple types)in the data store.
- DiscriminatorColumn - gets the discriminator column for this association if it requires a discriminator column.
The following example shows you how to access all one-to-many associations from your domain model:
private string GetMetaForeignKeyAssociations(Telerik.OpenAccess.Metadata
.MetadataContainer container)
{
StringBuilder sb = new StringBuilder();
foreach (MetaAssociation metaAssociation in container.Associations)
{
sb.AppendFormat("\nType: {0}", metaAssociation.AssociationType);
MetaForeignKeyAssociation oneToMany = metaAssociation as MetaForeignKeyAssociation;
if(oneToMany == null )
{
continue;
}
sb.AppendFormat("\n\tSource: {0}", oneToMany.Source.Name);
sb.AppendFormat("\n\tTarget: {0}", oneToMany.Target.Name);
}
return sb.ToString();
}
Private Function GetMetaForeignKeyAssociations(ByVal container As _
Telerik.OpenAccess.Metadata.MetadataContainer) As String
Dim sb As New StringBuilder()
For Each _metaAssociation As MetaAssociation In container.Associations
sb.AppendFormat(vbLf & "Type: {0}", _metaAssociation.AssociationType)
Dim oneToMany As MetaForeignKeyAssociation = _
TryCast(_metaAssociation, MetaForeignKeyAssociation)
If oneToMany Is Nothing Then
Continue For
End If
sb.AppendFormat(vbLf & vbTab & "Source: {0}", oneToMany.Source.Name)
sb.AppendFormat(vbLf & vbTab & "Target: {0}", oneToMany.Target.Name)
Next _metaAssociation
Return sb.ToString()
End Function