Forum:  Designer

Thread:  Set Entity Name Prefix Automatically from the Schema / Group


bdavis (User)   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 (Support Team)   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:
Code:
// 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...


Otis (LLBLGen Pro Team)   Posted on: 16-Jul-2019 10:59:19.
We'll think about adding this in a future version.