Change project TargetNames programmatically using .lgp file

Posts   
 
    
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 17-Jul-2007 21:48:43   

Suppose I have a table EMP (EMP_ID,EMP_NAME)

Then I create llblgen project and generate .lgp file

Then EMP table changed physically in DB to Employee(ID,Name)

Now, I want to be able to open .lgp file and change the DB Names (Target Names) programmatically (depend on desinger schema Refreshing will not be good in a massive db renaming which is our case)

i try this,

Dim project As ApplicationCore.Project
Dim entity As ApplicationCore.Entities.EntityDefinition
Dim field As ApplicationCore.Entities.EntityFieldDefinition

project = ApplicationCore.Project.Load("C:\Test.lgp")

For Each entity In pro.Entities

     For Each field In entity.Fields
                field.TargetName = GetNewFieldName(entity.Name, field.FieldName)
     Next

     entity.TargetName =  GetNewEntityName(entity.Name)

Next

Project.Save

The problem is that field.TargetName and Entity.TargetName is ReadOnly

How can I change the names programmatically? What is the interface the designer use to change these name when refreshing schema?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 18-Jul-2007 11:07:52   

If it's just direct table renames, the refresher can deal with that pretty good, though if you want to do it in code, be sure to use the load code as it is used in the commandline refresher or generator sourcecode. Use that as a starting point.

Then, rename the names on the DBTable objects in the DBSchema objects in the DBCatalog objects in the catalogs collection of the project.

There's a catch though: in DBSchema.Tables, the tables are stored with their name as key. So to rename them, simply do this: - create a new SortedList, - add the DBTable objects one by one from the old sorted list to the new sorted list with their new name as key and also set the DBTable.TableName to the new name. - set DBSchema.Tables to the new sorted list

Be sure to create a backup of your .lgp file first. Entities refer to their DBTable objects or DBView objects where they mapped on. So just renaming the DBTable object by setting its own property should be ok.

Frans Bouma | Lead developer LLBLGen Pro