Ability to Name the Foreign Keys Properties as the actual column name.

May 9, 2013 at 10:24 PM
New Feature: Allow to generate Foreign Keys properties with the actual name of the column instead of the Foreign Referenced by the ForeignKey Table Name.
CheckBox says: (under "Include Foreign Keys" CheckBox reads as "Name as Foreign Table"), since it depends of it.

Example (checkbox un-checked):
public virtual Materials PrincipalMaterial { get; set; }
public virtual Materials SecundaryMaterial { get; set; }
instead of (checkbox checked, this was the by-default behavior)
public virtual Materials Materials { get; set; }
public virtual Materials Materials { get; set; }
In cases when the property is created by a Column named like "cod_PrincipalMaterial", exist the posibility to add the "cod_" prefix for removal in generation process.

This Feature was uploaded in:
Hope you find it useful, just let me know.
May 13, 2013 at 9:47 PM
It's a super useful feature! In fact, there is also a similar problem when include "Has Many" option is used and there are multiple reference to a table from one or more other tables.

A couple of modification worked for me (ByCodeMapping, Camel Case Property Generation, Include Foreign Keys, NO Name as Foreign Table and Include "Has Many"):

ByCode\DBColumnMapper.cs : Bag :

if (_language == Language.CSharp)
                    "\t\t\tBag(x => x.{0}, colmap =>  {{ colmap.Key(x => x.Column(\"{1}\")); colmap.Inverse(true); }}, map => {{ map.OneToMany(); }});",
                    _applicationPreferences.NameFkAsForeignTable ? formatter.FormatPlural(hasMany.Reference) : formatter.FormatPlural(hasMany.Reference + hasMany.ReferenceColumn),

CodeGenerator.cs : GetCompileUnit :
foreach (var hasMany in Table.HasManyRelationships)
                    if (appPrefs.Language == Language.CSharp)
                        newType.Members.Add(codeGenerationHelper.CreateAutoProperty(string.Format("{0}<{1}{2}>", appPrefs.ForeignEntityCollectionType, appPrefs.ClassNamePrefix, pascalCaseTextFormatter.FormatSingular(hasMany.Reference)),
                            appPrefs.NameFkAsForeignTable ? Formatter.FormatPlural(hasMany.Reference) : Formatter.FormatPlural(hasMany.Reference + hasMany.ReferenceColumn), //Formatter.FormatPlural(hasMany.Reference),
                        constructorStatements.Add(new CodeSnippetStatement(string.Format(TABS + "{0} = new {1}<{2}{3}>();",
                            appPrefs.NameFkAsForeignTable ? Formatter.FormatPlural(hasMany.Reference) : Formatter.FormatPlural(hasMany.Reference + hasMany.ReferenceColumn), //Formatter.FormatPlural(hasMany.Reference),
                            codeGenerationHelper.InstatiationObject(appPrefs.ForeignEntityCollectionType), appPrefs.ClassNamePrefix, pascalCaseTextFormatter.FormatSingular(hasMany.Reference))));
  1. So I used the preference NameFkAsForeignTable ("Name as Foreign Table") in combination with IncludeHasMany ("Include ''Has Many""), because I find it convenient. If you agree, it may be under the two options in preference window.
  2. I used "hasMany.Reference + hasMany.ReferenceColumn" because I had references from multiple tables, with the same field name to the same refenced key.... Anyway...
  3. Similar code needed for VB and other code mapping options.
Thanks for the feature!