Version 2, Polymorphism, and Generics

Posts   
 
    
Barney
User
Posts: 29
Joined: 27-Jul-2005
# Posted on: 30-Jan-2007 03:13:59   

I'm converting a LLBL 1 project to LLBL 2. I'm using self-servicing and VS 2005 with VB.Net.

There is one module written by another programmer that uses polymorphism. It has a variable of EntityCollectionBase, and then, depending on what the user selects it creates it as a new WhateverCollection. Code in the rest of the module can add or delete the entities in the collection no matter what kind of entity it is.

I am having a hard time recreating this polymorhism in LLBL 2 which uses Generics.

Private m_colListItems As EntityCollectionBase

m_colListItems = New ListSampleSourceCollection() m_colListItems.GetMulti(Nothing)

or

m_colListItems = New ListSampleTypeCollection() m_colListItems.GetMulti(Nothing)

In LLBL2 there is no EntityCollectionBase, it's EntityCollectionBase(Of T) which messes up the polymorphism. Is there some other object I can use?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Jan-2007 08:11:00   

You can define the SuperType as an IEntityCollection or as EntityCollectionBase<EntityBase>.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Jan-2007 10:08:26   

Recommended is the IEntityCollection approach

Frans Bouma | Lead developer LLBLGen Pro
Barney
User
Posts: 29
Joined: 27-Jul-2005
# Posted on: 30-Jan-2007 12:20:20   

The IEntityCollection cleared up many problems - except these two:

'AddNew' is not a member of 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'

entListItem = CType(m_colListItems.AddNew(), EntityBase)

and

'Items' is not a member of 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'.

entListItem = CType(m_colListItems.Items(CInt(e.Cell.Row.Cells(COL_COLLECTION_INDEX).Value)), EntityBase)

Is it still posible to use polymorphism or do I have to use a select case statement or something like that?

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 30-Jan-2007 15:27:22   

Hi,

You may replace the first problem with :


entListItem = colListItems.EntityFactoryToUse.Create()
colListItems.Add(entListItem)

and for the second one, you can simply remove "Items" and use the indexer :


entListItem = CType(m_colListItems(CInt(e.Cell.Row.Cells(COL_COLLECTION_INDEX).Value)), EntityBase)

Barney
User
Posts: 29
Joined: 27-Jul-2005
# Posted on: 30-Jan-2007 15:36:51   

Works great - one note is that I had to change the first line to:

entListItem = CType(m_colListItems.EntityFactoryToUse.Create(), EntityBase)

or I get:

Option Strict On disallows implicit conversions from 'SD.LLBLGen.Pro.ORMSupportClasses.IEntity' to 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase'.

Thanks for the help!

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 30-Jan-2007 15:47:33   

yeah I forgot the cast ! wink