Batch rename

Posts   
 
    
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 09-Jan-2019 21:53:00   

I have about a dozen wide tables with columns that have the same naming prefix. As an easy example, imagine Customer table with columns named CustomerFirstName, CustomerLastName, CustomerPhone, CustomerEmail, etc.

I would like to remove all of those prefixes without doing "F2 > (edit) > Enter" more than 200 times. Is there any way to do this in the designer? This is for version 5.4.2.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jan-2019 05:58:11   

Hi Joel,

You could write a plugin.

Another way is to use the Element Search. It's commonly used for search objects into the project, but you also can perform actions in such queries. To do that:

  1. Open **Menu Project -> Search for Elements ** (Ctrl+F3).
  2. In 'Element Type' select 'Enumerable'
  3. Write this in the query area:
var entity = p.EntityModel.Vertices.FirstOrDefault(e=>e.Name=="Customer");
var prefix = entity.Name;

var fields = p.GetAllFieldsForGroupableModelElement(entity);
var newNames = new List<String>();
foreach(var f in fields)
{
    f.Name = f.Name.Replace(prefix, string.Empty);
    newNames.Add(f.Name);       
}

return newNames;
  1. Click 'Run Query'. That's it.

Above example would run it for just one entity named 'Customer'. If you want to run on every entity in the project, this would be the query:

var newNames = new List<String>();
var allEntities = p.EntityModel.Vertices;

foreach(var entity in allEntities)
{
    var prefix = entity.Name;

    var fields = p.GetAllFieldsForGroupableModelElement(entity);    
    foreach(var f in fields)
    {
        f.Name = f.Name.Replace(prefix, string.Empty);
        newNames.Add(entity.Name + "." + f.Name);       
    }
}

return newNames;

Hope that helps wink

David Elizondo | LLBLGen Support Team
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 10-Jan-2019 16:12:19   

Yes, that's exactly what I need. For some reason, I completely forgot about element search.