Skip to content

Commit

Permalink
739 Add ability to automatically add enum tables programatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjh37 committed Jan 20, 2022
1 parent 2009529 commit c10aad9
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 93 deletions.
27 changes: 27 additions & 0 deletions BuildTT/BuildTT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private static void CreateTT(string generatorRoot, string ttRoot)
// Enumerations ***********************************************************************************************************************
// Create enumerations from database tables
// List the enumeration tables you want read and generated for
// Also look at the AddEnum callback to add your own
Settings.Enumerations = new List<EnumerationSettings>
{
// Example
Expand Down Expand Up @@ -402,6 +403,32 @@ private static void CreateTT(string generatorRoot, string ttRoot)
}
};
Settings.AddEnum = delegate (Table table)
{
/*if (table.HasPrimaryKey && table.PrimaryKeys.Count() == 1 && table.Columns.Any(x => x.PropertyType == ""string""))
{
// Example IF to only choose tables with a certain naming conventions for enums
if (table.NameHumanCase.StartsWith(""REF_"", StringComparison.InvariantCultureIgnoreCase) ||
table.NameHumanCase.EndsWith(""_LUT"", StringComparison.InvariantCultureIgnoreCase))
{
try
{
Settings.Enumerations.Add(new EnumerationSettings
{
Name = table.NameHumanCase + ""Enum"",
Table = table.Schema.DbName + ""."" + table.DbName,
NameField = table.Columns.First(x => x.PropertyType == ""string"").DbName, // Or specify your own
ValueField = table.PrimaryKeys.Single().DbName // Or specify your own
});
}
catch
{
// Swallow exception
}
}
}*/
};
// Use the following function if you need to apply additional modifications to a enum
// Called just before UpdateEnumMember
Settings.UpdateEnum = delegate (Enumeration enumeration)
Expand Down
27 changes: 27 additions & 0 deletions EntityFramework.Reverse.POCO.Generator/Database.tt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
// Enumerations ***********************************************************************************************************************
// Create enumerations from database tables
// List the enumeration tables you want read and generated for
// Also look at the AddEnum callback to add your own
Settings.Enumerations = new List<EnumerationSettings>
{
// Example
Expand Down Expand Up @@ -386,6 +387,32 @@
}
};

Settings.AddEnum = delegate (Table table)
{
/*if (table.HasPrimaryKey && table.PrimaryKeys.Count() == 1 && table.Columns.Any(x => x.PropertyType == "string"))
{
// Example IF to only choose tables with a certain naming conventions for enums
if (table.NameHumanCase.StartsWith("REF_", StringComparison.InvariantCultureIgnoreCase) ||
table.NameHumanCase.EndsWith("_LUT", StringComparison.InvariantCultureIgnoreCase))
{
try
{
Settings.Enumerations.Add(new EnumerationSettings
{
Name = table.NameHumanCase + "Enum",
Table = table.Schema.DbName + "." + table.DbName,
NameField = table.Columns.First(x => x.PropertyType == "string").DbName, // Or specify your own
ValueField = table.PrimaryKeys.Single().DbName // Or specify your own
});
}
catch
{
// Swallow exception
}
}
}*/
};

// Use the following function if you need to apply additional modifications to a enum
// Called just before UpdateEnumMember
Settings.UpdateEnum = delegate (Enumeration enumeration)
Expand Down
Loading

0 comments on commit c10aad9

Please sign in to comment.