Common Base Class for Enitity Collections

Posts   
 
    
Posts: 7
Joined: 10-Sep-2008
# Posted on: 16-Jul-2009 15:04:46   

I am working on an existing project inwhich cancelling the changes to an entity was never wired up in our base form. Our base form has a MainObect which is an EntityBase and we also have a hashtable containing the related child entities we are also able to edit on this form.

I would like to somehow cast the objects in the hashtable to something Generic that I can then call the Refetch method on without knowning the specific instance of the collection class.

I wish I could cast an Object to EntityCollectionBase(of EnitityBase) but this is not in the hierachy. If this was possible I could the check if the collection has changes and if it does then refetch the entity if it is dirty or remove it from the collection if it is new.

Any suggestions on finding a common class that I can cast the related child entities object to would be great. If I refecth the main object it only refetchs the main object and not the related entities.

We are using self service and Net 2.0 of llblgen.

A later version would create a clone of the mainobject and its child entities and then just swap it out on Cancel.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jul-2009 01:11:29   

Sorry. I don't understand you 100%, but I think you are looking for the IEntity interface. That interface has the Refetch method.

Could you show us some code of what you are trying to achieve?

David Elizondo | LLBLGen Support Team
Posts: 7
Joined: 10-Sep-2008
# Posted on: 28-Jul-2009 16:08:02   

Thanks for the input. This part of the app was written in VS2003 before Generics and my employment here.

Here is what I was able to do.

If _registeredCollections.Count > 0 Then For Each obj As DictionaryEntry In _registeredCollections Dim ec As IEntityCollection = DirectCast(obj.Value, IEntityCollection)

                        If ec.ContainsDirtyContents Then
                            Dim x As Integer = 0
                            Do While x < ec.Count
                                If TypeOf (ec(x)) Is EntityBase Then
                                    Dim entBase As EntityBase = DirectCast(ec(x), EntityBase)

                                    If entBase.IsNew Then
                                        ec.Remove(entBase)
                                    Else
                                        entBase.Refetch()
                                        x += 1
                                    End If

                                End If
                            Loop
                        End If
                    Next

                End If
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Jul-2009 20:04:16   

And does this code no longer work? What is the problem with this code ?

Matt

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Jul-2009 08:40:27   

And which LLBLGen Pro runtime library version are you using?

Posts: 7
Joined: 10-Sep-2008
# Posted on: 30-Jul-2009 00:02:11   

Sorry,

The code I posted above was my solution.