Hi, (Using Ver 2.00/VB/Adapter/SQL 2K)
In the following, Div has a 1:m relationship with DivProg & Section based on the PK of DivCode. I've been using the following code to determine if a Div PK has any related records in DivProg or Section:
Dim arrRelations() As EntityField2 = {DivProgFields.DivCode, SectionFields.DivCode}
If Utilities.AnyRelatedRecords(arrRelations, PK) = True Then
by passing an array of relations to:
Public Shared Function AnyRelatedRecords(ByVal arrRelations As Array, ByVal aForeignKey As String) As Boolean
Dim result As Boolean
For Each eField As EntityField2 In arrRelations
If GetRelatedRecords(eField, aForeignKey) > 0 Then
result = True
Exit For
Else
result = False
End If
Next eField
Return result
End Function
- If the PK was a compound key (eg DivCode+ProgCode), how would I specify this to pass the array relations?
Dim arrRelations() As EntityField2 = {DivProgFields.DivCode, SectionFields.DivCode}
- Is there a better way of doing it? eg Not quite sure if this is a count of related records:
Dim division As New DivEntity(aPK)
If division.DivProg.Count > 0 Or _
division.Section.Count > 0 Then
'Related records
End If
Any takers