Home > Developing Using CodeFluent Entities, SharePoint, SQL Server, SQLAzure > Implementing a Custom Naming Convention in CodeFluent Entities

Implementing a Custom Naming Convention in CodeFluent Entities

We previously introduced naming conventions in CodeFluent Entities and the ones built-in in the product, and in this previous post we mentioned the fact that you could create your own naming convention.

To do so you can either derive from the INamingConvention interface and start it from scratch, or derive from an existing one to extend it.

For instance here’s a custom naming convention, deriving form the built-in BaseNamingConvention, and which names column names as Default_[TableName]_[ColumnName], and names constraints as “myx_[ConstraintType]_[TableName]_[ReferencedTableName]”:

 public class MyCustomConvention: BaseNamingConvention
  public override string GetName(INamedObject obj, IDictionary context)
   Column column = obj as Column;
   if (column != null)
    string name = (string)context["name"];
    Table table = (Table)context["table"];
    if (table != null)
      column.DefaultName = "Default_" + table.Name + "_" + name;
   return base.GetName(obj, context);

  public override string GetShortName(IShortNamedObject obj, IDictionary context)
   Constraint constraint = obj as Constraint;
   if (constraint == null)
    return base.GetShortName(obj, context);

   return "myx_" + constraint.ConstraintType + "_" + constraint.Table.Name + "_" + constraint.ReferencedTable.Name;

You can then use the custom naming convention either in an assembly or a XML file, and reuse it in all your models.

In fact, you’ll find a complete example of this in the product documentation: Naming Conventions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s