Convert existing entity to supertype/subtype

Posts   
 
    
ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 10-Sep-2020 01:22:56   

I'm using LLBLGen 5.7, Adapter

I currently have a BaseEntity that has a subtype ChildEntity, using TargetPerEntity. Now I have introduced GrandchildEntity, which is a subtype of ChildEntity. Existing ChildEntitys need to be converted to GrandchildEntitys. That is, for each ChildEntity I need to * Read the ChildEntity * Create a new GrandchildEntity that has the same key field as the ChildEntity * Copy some properties from the ChildEntity to the GrandchildEntity * Save the GrandchildEntity

The problem is that the GrandChildEntity is new, so the framework tries to create new ChildEntity and BaseEntity records when I save it. Is there a way to make it temporarily act as if the GrandchildEntity is not a subtype, so it only saves the GrandchildEntity?

All the other approaches I've considered involve direct database inserts.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Sep-2020 06:52:51   

As this is considered a migration, I would recommend to run a DB script to so. However another approach would be to map the entity a second time not being part of inheritance, i.e.:GrandchildOnlyEntity. Then you can use it independently for migrations.

Another approach, that would be valid considering what you are doing (migrating), is to delete ChildEntity and then create GrandchildEntity.

David Elizondo | LLBLGen Support Team
ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 10-Sep-2020 19:18:15   

I simplified my original explanation, but I can't do the conversion with straight DB script because the conversion has to deserialize some data that's stored in ChildEntity and use that to create the GrandchildEntity. Also can't easily delete and recreate because of foreign keys. Well, I guess I cold disable them all temporarily.

Anyway your idea to map a new entity is great and seems simpler than anything I've come up with so far. Thanks!