Request for EntityBase.EntityType

Posts   
 
    
malepuz
User
Posts: 3
Joined: 23-Mar-2005
# Posted on: 06-May-2005 15:58:40   

Is there a way to get at the EntityType Enum value of an EntityBase Object? I am asking because a select case for an enumerated type goes directly to that case without going through every case as it does with strings and in an if elseif statement. The EntityBase object has data and I would like to use something like:

dim MyEntityBase as EntityBase=SelectedNode() Select Case MyEntityBase.EntityType Case CustomerEntity Display(directcast(MyEntityBase,CustomerEntity)) Case EmployeeEntity Display(directcast(MyEntityBase,EmployeeEntity)) Case OrderEntity Display(directcast(MyEntityBase,OrderEntity)) Case Else Display(MyEntityBase) End Select

Rather than using: If (typeOf MyEntityBase is CustumerEntity) then Display(directcast(MyEntityBase,CustomerEntity) elseif (typeOf MyEntityBase is EmployeeEntity) then Display(directcast(MyEntityBase,EmployeeEntity) elseif (typeOf MyEntityBase is OrderEntity) then Display(directcast(MyEntityBase,OrderEntity) else Display(MyEntityBase) end if

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-May-2005 18:16:59   

It's not build in, but you can add it yourself with 1 include template: In there you generate a property which returns the EntityType. enum value. You then bind that template to one of the Custom_ template id's defined for the entity classes: Custom_EntityAdapterTemplate for adapter entities, Custom_EntityBaseTemplate for entity base classes in selfservicing/2 class scenario, Custom_EntityTemplate for entity classes in selfservicing, general scenario or Custom_EntityUsingEntityBaseTemplate for the entity classes derived from the base classes in selfservicing, two class scenario.

The property temlate code looks like:

Public ReadOnly Property EntityTypeValue Get Return EntityType.<[ CurrentEntityName ]>Entity End Get End Property

Please see the TemplateStudio's documentation for a tutorial how to create a custom template set and an include template in a couple of easy steps.

Frans Bouma | Lead developer LLBLGen Pro
malepuz
User
Posts: 3
Joined: 23-Mar-2005
# Posted on: 08-May-2005 19:11:52   

Otis, your solution is very elegant but I don't need it that often. For right know I continue with the if... elseif... else... endif. I thik this will be a feature worth adding to future releases.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 08-May-2005 23:34:30   

malepuz wrote:

Otis, your solution is very elegant but I don't need it that often. For right know I continue with the if... elseif... else... endif. I thik this will be a feature worth adding to future releases.

I second this. I have come across cases where having the entityType on the entity would be very helpful (not for the same reasons as the original poster).

I haven't had a chance to play with Template Studio yet (looking forward to it when I finally have some time simple_smile ), so generating this property is currently not an option for me.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-May-2005 09:31:30   

It's on the TODO list.

Frans Bouma | Lead developer LLBLGen Pro
Jazz
User
Posts: 63
Joined: 12-Aug-2005
# Posted on: 12-Aug-2005 17:56:42   

Hello there, if I understood that right you can do it this way:

EntityType et = new EntityType(); EntityType entityType = (EntityType)EntityType.Parse(et.GetType(), yourInstance.GetType().Name);

Regards, André