GetDependingRelatedEntities

Posts   
 
    
Heather
User
Posts: 17
Joined: 16-Jan-2009
# Posted on: 06-Feb-2009 19:33:27   

I'm using v2.6 Adapter.

How can I get a list of dependant entities from a containing entity. I was hoping to use GetDependingRelatedEntities but that does not seem to do anything with collections of depending entities. Example:

I have two tables, Equipment and EquipmentEvent. Equipment is keyed on EquipmentID. EquipmentEvent is keyed on EquipmentEventID with a required FK of EquipmentID. One piece of Equipment can have many EquipmentEvents. When I look at the GetDependingRelatedEntities() call in EquipmentEntity I expected to see something that added the EquipmentEventEntity objects in _equipmentEvent to return but the sub is empty.

My end goal is for validating. I want to call a validate routine on the EquipmentValidator that walks all children and validates those without having to specify exactly what they all are. We call the Validate directly from our UI and do not wait for the Save code so I can't wait and let the automatic calling of the validate from the internal save code to kick in.

Thanks,

Heather

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Feb-2009 04:00:28   

Hi Heather,

This is the easiest way I know for doing that:

ObjectGraphUtils graphUtils = new ObjectGraphUtils();
List<IEntity2> relatedInGraph =  graphUtils .ProduceTopologyOrderedList(order);

Then you can traverse for the objects and look for those that are dirty:

foreach (IEntity2 e in relatedInGraph)
{
     if (e.IsDirty)
     {
              // validate
     }
}
David Elizondo | LLBLGen Support Team
Heather
User
Posts: 17
Joined: 16-Jan-2009
# Posted on: 09-Feb-2009 15:02:27   

So what exactly is GetDependingRelatedEntities supposed to do? The comment at the top of the routine states "Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields)".

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Feb-2009 15:06:33   

Is the Event.EquipmentEvent collection already fetched from the database? Or do you want to fetch them?

GetDependingRelatedEntities fetches nothing it just return the already attached entities.

Heather
User
Posts: 17
Joined: 16-Jan-2009
# Posted on: 09-Feb-2009 15:21:22   

Its already fetched. And its not really a matter of whether its fetched or not. If I look at the generated code for the EquipmentEntity it is as follows:

Public Overrides Function GetDependingRelatedEntities() As List(Of IEntity2) Dim toReturn As New List(Of IEntity2)() Return toReturn End Function

So its not even referencing the EquipmentEventEntity collection. I just re-searched and it is referenced in GetMemberEntityCollections so maybe the documentation is just a little mis-guided?

Does GetDependingRelatedEntities just return any depending entities that are 1:1 and GetMemberEntityCollections returns and depending entities that are 1:n?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Feb-2009 10:02:42   

Have you hidden the relation on 1 side or the field mapped onto the relation in one side? Because if so, the code won't emit anything:


''' <summary>Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These
''' entities will have to be persisted after this entity during a recursive save.</summary>
''' <returns>Collection with 0 or more IEntity2 objects, referenced by this entity</returns>
Public Overrides Function GetDependingRelatedEntities() As List(Of IEntity2)
    Dim toReturn As New List(Of IEntity2)()
<[Foreach RelatedEntity OneToOne CrLf]><[If Not MappedFieldRelationIsHidden]><[ If Not IsOneToOnePkPk FkSide ]>         If Not _<[CaseCamel MappedFieldNameRelation]> Is Nothing Then
        toReturn.Add(_<[CaseCamel MappedFieldNameRelation]>)
    End If<[EndIf]>
<[ If Not IsOneToOnePkFkUc FkSide ]>            If Not _<[CaseCamel MappedFieldNameRelation]> Is Nothing Then
        toReturn.Add(_<[CaseCamel MappedFieldNameRelation]>)
    End If<[EndIf]><[EndIf]><[NextForeach]>
<[If IsSubType]>            toReturn.AddRange(MyBase.GetDependingRelatedEntities())<[EndIf]>
    Return toReturn
End Function

Frans Bouma | Lead developer LLBLGen Pro
Heather
User
Posts: 17
Joined: 16-Jan-2009
# Posted on: 10-Feb-2009 13:36:35   

No, I haven't hidden either relation. When I look in the LLBL designer Equipment has a 1:n relation with EquipmentEvent and EquipmentEvent has a m:1 relation with Equipment and neither is hidden. I've attached the project file for review if that helps.

(I've deleted the attachment, as it's no longer needed -- Otis)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Feb-2009 15:47:12   

Ah, I see what's the confusion: GetDependingRelatedEntities is for obtaining the 1:1 related entities, if you want the 1:n related depending entities, use GetMemberCollections.

Frans Bouma | Lead developer LLBLGen Pro
Heather
User
Posts: 17
Joined: 16-Jan-2009
# Posted on: 10-Feb-2009 15:54:06   

OK thank you. That's what I had finally come to in an earlier post but wanted it confirmed before I coded to it.