EntityManager and EntityCollection

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 03-Nov-2004 12:20:06   

Greetings,

I have a BusinessObject assembly that references both the DAL and DALSepecific assemblies generated by LLBL. In the BusinessObject assembly I have a GL class the extends the GLEntity class. In this GL class I would expose all services necessary for the UI developer. One of the services exposed by this GL class is a LoadList(filterBucket) that returns an EntityCollection. My problem is as follows:

When the UI uses code like this

Dim col As EntityCollection = GLMoney.LoadList(filterBucket)
Dim obj As GL
For i As Integer = 0 To col.Count - 1
    obj = CType(col(i), GL)
    Console.WriteLine(i.ToString & "==> " & obj.GLId )
Next

the problem with this code is that I get a run-time error on the line

 CType(col(i), GL) 

the only way this would run is to change the CType to

Dim obj As GLGLEntity
CType(col(i), GLEntity) 

My problem here is the inconsistency that the UI developer is experiencing. I want the UI developer to only use (and preferably only see) the GL type and at the same time I want the UI developer to have the flexibility of building filter buckets (which require a reference to the Field index's ENUMs and the relations collection of each entity). In other wards, I want all UI interaction to be done through my extended class (GL) and NOT through the entity class (GLEntity).

I tried building a factory class for GL (GLFactory) by following the code in the GLEntityFactory. Whenever I used the GLFactory (instead of GLEntityFactory) in creating a EntityCollection, I would get a Null Reference run-time error when executing

 adapter.FetchEntityCollection(...) 

My GLFactory is as follows:

 <Serializable()> _
Public Class GLFactory
    Implements IEntityFactory2

    Public Sub New()
    End Sub

    Public Overridable Overloads Function Create() As IEntity2 Implements IEntityFactory2.Create
        Return New GL
    End Function


    Public Overridable Overloads Function Create(ByVal fields As IEntityFields2) As IEntity2 Implements IEntityFactory2.Create
        Return New GL(fields)
    End Function


    Public Overridable Function CreateFields() As IEntityFields2 Implements IEntityFactory2.CreateFields
        Return EntityFieldsFactory.CreateEntityFieldsObject(EntityType.GLEntity)
    End Function

I also had to add this constructor to the GL class

public Sub New(ByVal fields As IEntityFields2)
    MyBase.New("GL")
End Sub

I don't know if there is a better way to handle this structure. I thought I am following what FRANS is recommending and what I gathered from this forum. I hope there is a better way to handle this... please help confused

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 03-Nov-2004 18:21:29   

Have you checked out the derived-entity templates in the 3rd party section on the website? THey're in C# and VB.NET and they illustrate what you want: for each entity a derived class, typed collection and factory.

They prefix everything with 'My', but you can easily change that in the templates (there are just 2 templates, so that's easy) and in the .config files to something you want to use. If you have problems with using these templates, please let me know.

Frans Bouma | Lead developer LLBLGen Pro