Set Entity Name Prefix Automatically from the Schema / Group

Posts   
 
    
bdavis
User
Posts: 7
Joined: 23-Jan-2019
# Posted on: 15-Jul-2019 14:57:59   

Is it possible to have a prefix added automatically to the entity class name based on the Schema / Group it is in?

Example Schema Name: payments Table Name: tbl_Batch

Generated Entity Class Name: Payments_BatchEntity ??

I'm not currently seeing any quick way of doing this in the designer / project settings, besides manually setting it on the Reverse-Engineer Entity dialog.

Using: - LLBLGen Pro Framework - SQL Server - Designer Version 5.5

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Jul-2019 08:25:52   

An idea is to use the "Search for elements" feature in the designer (Menu Project -> Search for elements). Then select Enumerable for the element type. Then paste the following in the query area:

// obtain mapping data
var mappingData = p.MappingData.MappingDataPerDriverID[0];
var mappings = mappingData.EntityMappings;

// used facilitares the camel conversion
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

// process each mapping
var proccessedEntities = new List<string>();
foreach(EntityMapping mapping in mappings)
{
    // find names in the mapping
    var tableName = mapping.MappedTarget.Name;
    var schemaName = mapping.MappedTarget.ContainingSchema.SchemaOwner;
    var newName = textInfo.ToTitleCase(schemaName) + tableName;
    proccessedEntities.Add(newName);
    
    // find the entity and change the name
    EntityDefinition entity = p.EntityModel.Vertices.FirstOrDefault(x => x.Name == mapping.MappedEntity.Name);
    entity.Name = newName;
}

return proccessedEntities;

... if that works, you could convert this into a plugin. You can attach plugin events into designer events (such as add new entity), so the conversion takes place automatically. more info here...

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39747
Joined: 17-Aug-2003
# Posted on: 16-Jul-2019 10:59:19   

We'll think about adding this in a future version.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39747
Joined: 17-Aug-2003
# Posted on: 14-Jan-2020 11:38:32   

Implemented in v5.7.

Frans Bouma | Lead developer LLBLGen Pro
bdavis
User
Posts: 7
Joined: 23-Jan-2019
# Posted on: 14-Jan-2020 13:21:16   

Awesome! Can't wait to try this new feature out! smile