Skip to content

Commit fed8e09

Browse files
authored
Merge pull request #466 from jbaig/manytomanyrename
Resolves #465 for many to many relationships to rename the property names. Thanks to jbaig
2 parents b944365 + 767d4c5 commit fed8e09

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@
249249
return name;
250250
};
251251

252+
// Mapping Table renaming *********************************************************************************************************************
253+
// By default, name of the properties created relate to the table the foreign key points to and not the mapping table.
254+
// Use the following function to rename the properties created by ManytoMany relationship tables especially if you have 2 relationships between the same tables.
255+
// Example:
256+
Settings.MappingTableRename = (string mappingtable, string tablename, string entityname) =>
257+
{
258+
259+
// Examples:
260+
// If you have two mapping tables such as one being UserRequiredSkills snd one being UserOptionalSkills, this would change the name of one property
261+
// if (mappingtable == "UserRequiredSkills" and tablename == "User")
262+
// return "RequiredSkills";
263+
264+
// or if you want to give the same property name on both classes
265+
// if (mappingtable == "UserRequiredSkills")
266+
// return "UserRequiredSkills";
267+
268+
return entityname;
269+
};
270+
252271
// Column modification*****************************************************************************************************************
253272
// Use the following list to replace column byte types with Enums.
254273
// As long as the type can be mapped to your new type, all is well.

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.Core.ttinclude

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
public static string[] AdditionalForeignKeysDataAnnotations;
136136
public static string ConfigFilePath;
137137
public static Func<string, string, bool, string> TableRename;
138+
public static Func<string, string, string, string> MappingTableRename;
138139
public static Func<StoredProcedure, string> StoredProcedureRename;
139140
public static Func<string, StoredProcedure, string> StoredProcedureReturnModelRename;
140141
public static Func<Column, Table, Column> UpdateColumn;
@@ -4133,7 +4134,9 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
41334134
return;
41344135

41354136
var leftPropName = leftTable.GetUniqueColumnName(rightTable.NameHumanCase, right, checkForFkNameClashes, false, Relationship.ManyToOne); // relationship from the mapping table to each side is Many-to-One
4137+
leftPropName = Settings.MappingTableRename(Name, leftTable.NameHumanCase, leftPropName);
41364138
var rightPropName = rightTable.GetUniqueColumnName(leftTable.NameHumanCase, left, checkForFkNameClashes, false, Relationship.ManyToOne); // relationship from the mapping table to each side is Many-to-One
4139+
rightPropName = Settings.MappingTableRename(Name, rightTable.NameHumanCase, rightPropName);
41374140
leftTable.AddMappingConfiguration(left, right, leftPropName, rightPropName);
41384141

41394142
IsMapping = true;

0 commit comments

Comments
 (0)